关于merge into 报错,求指导

u012863855 2013-12-23 08:27:14
对于 merge into 有一个搞错是 在 on 中写了 列,而 update 中又更新了改列,则会报一个
无法更新 ON 子句中引用的列,
但是 我发现我们生产上 ,写了一个这样的情况即

merge into tbl a
(select col , col2
from tbl2) b
on (a.col = '2')
when matched then update
set a.col = b.col

但是没有报错,而且还更新成功了,很奇怪,请问大家知道为什么吗?
...全文
260 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
_拙计 2013-12-25
  • 打赏
  • 举报
回复
引用 3 楼 zlloct 的回复:
[quote=引用 2 楼 u012863855 的回复:] [quote=引用 1 楼 zlloct 的回复:] [quote=引用 楼主 u012863855 的回复:] 对于 merge into 有一个搞错是 在 on 中写了 列,而 update 中又更新了改列,则会报一个 无法更新 ON 子句中引用的列, 但是 我发现我们生产上 ,写了一个这样的情况即 merge into tbl a (select col , col2 from tbl2) b on (a.col = '2') when matched then update set a.col = b.col 但是没有报错,而且还更新成功了,很奇怪,请问大家知道为什么吗?
缺少关键字USING也能成功?[/quote] sorry,上面只是手写一个例子,漏了using,但是生产上确实跑成功了,有人知道为什么吗? merge into tbl a using (select col , col2 from tbl2) b on (a.col = '2') when matched then update set a.col = b.col[/quote] select col , col2 from tbl2返回多条数据还是单条数据??[/quote]估计就一条,不然它怎么更新
CT_LXL 2013-12-24
  • 打赏
  • 举报
回复
引用 2 楼 u012863855 的回复:
[quote=引用 1 楼 zlloct 的回复:] [quote=引用 楼主 u012863855 的回复:] 对于 merge into 有一个搞错是 在 on 中写了 列,而 update 中又更新了改列,则会报一个 无法更新 ON 子句中引用的列, 但是 我发现我们生产上 ,写了一个这样的情况即 merge into tbl a (select col , col2 from tbl2) b on (a.col = '2') when matched then update set a.col = b.col 但是没有报错,而且还更新成功了,很奇怪,请问大家知道为什么吗?
缺少关键字USING也能成功?[/quote] sorry,上面只是手写一个例子,漏了using,但是生产上确实跑成功了,有人知道为什么吗? merge into tbl a using (select col , col2 from tbl2) b on (a.col = '2') when matched then update set a.col = b.col[/quote] select col , col2 from tbl2返回多条数据还是单条数据??
u012863855 2013-12-24
  • 打赏
  • 举报
回复
引用 1 楼 zlloct 的回复:
[quote=引用 楼主 u012863855 的回复:] 对于 merge into 有一个搞错是 在 on 中写了 列,而 update 中又更新了改列,则会报一个 无法更新 ON 子句中引用的列, 但是 我发现我们生产上 ,写了一个这样的情况即 merge into tbl a (select col , col2 from tbl2) b on (a.col = '2') when matched then update set a.col = b.col 但是没有报错,而且还更新成功了,很奇怪,请问大家知道为什么吗?
缺少关键字USING也能成功?[/quote] sorry,上面只是手写一个例子,漏了using,但是生产上确实跑成功了,有人知道为什么吗? merge into tbl a using (select col , col2 from tbl2) b on (a.col = '2') when matched then update set a.col = b.col
CT_LXL 2013-12-23
  • 打赏
  • 举报
回复
引用 楼主 u012863855 的回复:
对于 merge into 有一个搞错是 在 on 中写了 列,而 update 中又更新了改列,则会报一个 无法更新 ON 子句中引用的列, 但是 我发现我们生产上 ,写了一个这样的情况即 merge into tbl a (select col , col2 from tbl2) b on (a.col = '2') when matched then update set a.col = b.col 但是没有报错,而且还更新成功了,很奇怪,请问大家知道为什么吗?
缺少关键字USING也能成功?

17,089

社区成员

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

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