merge into 错误

vstian 2009-09-10 04:23:01
merge into A a using B b
on(a.id_no = b.id_no)
when matched then update set a.sm_code=b.sm_code;


这句话报错 说缺少关键字???怎么修改阿
...全文
162 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
vstian 2009-09-10
  • 打赏
  • 举报
回复
多谢各位了
ojuju10 2009-09-10
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 vstian 的回复:]
update A a
set a.sm_code= (select sm_code from B b where a.id_no=b.id_no);


改成这样功能是一样的吗 ????
[/Quote]
加上where条件,
where a.id_no in (select id_no from b )
否则不满足条件的数据也被更新为null
shiyiwan 2009-09-10
  • 打赏
  • 举报
回复
汗。。。
[Quote=引用 7 楼 wildwave 的回复:]

楼主就试试加when not matched吧
想当初我就是通过merge into 认识shiyiwan的,嘿嘿
[/Quote]
shiyiwan 2009-09-10
  • 打赏
  • 举报
回复
后面要加exists判断的,否则子查询结果为NULL时会把a.sm_code也更新掉的
[Quote=引用 8 楼 vstian 的回复:]
update A a
set a.sm_code= (select sm_code from B b where a.id_no=b.id_no);


改成这样功能是一样的吗 ????
[/Quote]
小灰狼W 2009-09-10
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 vstian 的回复:]
update A a
set a.sm_code= (select sm_code from B b where a.id_no=b.id_no);


改成这样功能是一样的吗 ????
[/Quote]
要加个条件
update A a
set a.sm_code= (select sm_code from B b where a.id_no=b.id_no)
where exists(select 1 from b where id_no=a.id_no);
vstian 2009-09-10
  • 打赏
  • 举报
回复
update A a
set a.sm_code= (select sm_code from B b where a.id_no=b.id_no);


改成这样功能是一样的吗 ????
小灰狼W 2009-09-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 shiyiwan 的回复:]
9i用还要加when not matched then ....

update A a set a.sm_code = (select b.sm_code from B b where a.id_no = b.id_no ) where exists
(select 1 from B c where a.id_no = c.id_no );
[/Quote]
楼主就试试加when not matched吧
想当初我就是通过merge into 认识shiyiwan的,嘿嘿
shiyiwan 2009-09-10
  • 打赏
  • 举报
回复
9i用还要加when not matched then ....

update A a set a.sm_code = (select b.sm_code from B b where a.id_no = b.id_no ) where exists
(select 1 from B c where a.id_no = c.id_no );
ojuju10 2009-09-10
  • 打赏
  • 举报
回复
我仔细核对了语法真的没有问题

是在不行,就用子查询update吧
vstian 2009-09-10
  • 打赏
  • 举报
回复
9i 能使用merge into 吗


要是没有的话怎么执行这种功能 哈 ????
小灰狼W 2009-09-10
  • 打赏
  • 举报
回复
语法没问题
merge into 是9i里引入的
vstian 2009-09-10
  • 打赏
  • 举报
回复
9i 的哈 ,9i 能用吗 ???
ojuju10 2009-09-10
  • 打赏
  • 举报
回复

merge into A a using B b
on(a.id_no = b.id_no)
when matched then update set a.sm_code=b.sm_code;

语法没有错误,请问你的数据库版本是否为10g以及以上呢?

17,377

社区成员

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

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