update语句问题,更新不一致

bobacer 2011-12-28 11:47:59
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
...全文
151 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaobn_cn 2011-12-29
  • 打赏
  • 举报
回复
第1条,不知道楼主你是怎么理解出应当更新1条语句的,我分析你的update语句中没有where条件的,你那里所有的where都是子查询中的,自然就会更新所有记录。建议你仔细进行排版分析下SQL。

第2条,你的update语法本身就是错误的,oracle的update是不支持update ... set ... from ...这种语法的,一般来说如果使用其它表的数据来更新有两种方法,第1种方案是就你的第1条SQL中的例子,使用子查询做为赋值等号右侧的值,第2种使用视图更新的方式,大体用法如下:
update (select t1.a,t1.b,t2.c from t1,t2 where t1.a = t2.a) t3
set b = c ;
-- 上面这种语法要求select结果中包含要更新表的主键
mizuho_2006 2011-12-28
  • 打赏
  • 举报
回复
最下面那个更新语句,UPDATE 后接FROM是错的。。

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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