关于update语句问题,更新不一致的语句

bobacer 2011-12-28 01:42:17
BANCS_YYB_BAL 表有500条数据

select c.ACTNO,b.invm_curr_bal from bancs.t_invm_w01 b,BANCS_YYB_BAL c
where b.invm_memb_cust_ac=c.actno and b.INVM_CURRENCY='CNY' and substr(b.INVM_GL_CLASSIFICATION_CODE,13,4) in (select tgt_apcode from tgt_apcode_bancs where tgt_num in ('0019','1002')))
这条语句只有一条记录,
按照道理下面的语句应该只更新一条记录,可却把5000条记录都更新了,不知道为什么
update BANCS_YYB_BAL a set a.bal=(select tb.invm_curr_bal from (select c.ACTNO,b.invm_curr_bal from bancs.t_invm_w01 b,BANCS_YYB_BAL c
where b.invm_memb_cust_ac=c.actno and b.INVM_CURRENCY='CNY' and substr(b.INVM_GL_CLASSIFICATION_CODE,13,4) in (select tgt_apcode from tgt_apcode_bancs where tgt_num in ('0019','1002'))) tb
where tb.actno=a.actno)
下面的语句,始终报错ora-00933,在from的地方,
update BANCS_YYB_BAL a set a.bal=tb.invm_curr_bal
from (select c.ACTNO,b.invm_curr_bal from bancs.t_invm_w01 b,BANCS_YYB_BAL c
where b.invm_memb_cust_ac=c.actno and b.INVM_CURRENCY='CNY' and substr(b.INVM_GL_CLASSIFICATION_CODE,13,4) in (select tgt_apcode from tgt_apcode_bancs where tgt_num in ('0019','1002'))) tb
where tb.actno=a.actno
...全文
183 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
guanghuiy 2011-12-29
  • 打赏
  • 举报
回复

update BANCS_YYB_BAL a
set a.bal = (select tb.invm_curr_bal
from (select c.ACTNO,
b.invm_curr_bal
from bancs.t_invm_w01 b,
BANCS_YYB_BAL c
where b.invm_memb_cust_ac = c.actno
and b.INVM_CURRENCY = 'CNY'
and substr(b.INVM_GL_CLASSIFICATION_CODE, 13, 4) in
(select tgt_apcode
from tgt_apcode_bancs
where tgt_num in ('0019', '1002'))) tb
where tb.actno = a.actno)--这个条件是否会有一个actno对应多个invm_curr_bal?看不到数据,应该是条件没限制住 看看能否在加个其他条件在限制一下?

fandajun 2011-12-29
  • 打赏
  • 举报
回复
update BANCS_YYB_BAL a
set a.bal = (select tb.invm_curr_bal
from (select c.ACTNO, b.invm_curr_bal
from bancs.t_invm_w01 b, BANCS_YYB_BAL c
where b.invm_memb_cust_ac = c.actno
and b.INVM_CURRENCY = 'CNY'
and substr(b.INVM_GL_CLASSIFICATION_CODE, 13, 4) in
(select tgt_apcode
from tgt_apcode_bancs
where tgt_num in ('0019', '1002'))) tb
where tb.actno = a.actno)
这条语句相当于对整个BANCS_YYB_BAL 进行修改,后面还需要增加where条件
yjytiantang 2011-12-28
  • 打赏
  • 举报
回复
update BANCS_YYB_BAL a set a.bal=(select tb.invm_curr_bal from (select c.ACTNO,b.invm_curr_bal from bancs.t_invm_w01 b,BANCS_YYB_BAL c
where b.invm_memb_cust_ac=c.actno and b.INVM_CURRENCY='CNY' and substr(b.INVM_GL_CLASSIFICATION_CODE,13,4) in (select tgt_apcode from tgt_apcode_bancs where tgt_num in ('0019','1002'))) tb
where tb.actno=a.actno)
少了where 條件,更新的當然是全部數據了,外層括號外還應該再加where 條件
xpingping 2011-12-28
  • 打赏
  • 举报
回复
更新===>说明5000条都满足where条件




下面那个语句明显错的
select …… from table
bobacer 2011-12-28
  • 打赏
  • 举报
回复
就是不知道怎么限制啊
dinya2003 2011-12-28
  • 打赏
  • 举报
回复
你的where没限制住update的表数据。

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧