SQL 合并时出现 ORA-38104 错误的原因是什么?
我有这样的代码,
MERGE INTO target_table tgt
USING source_table src
on(tgt.c1=src.c1)
WHEN MATCHED THEN
UPDATE SET tgt.c1=src.c2
我收到 ORA-38104: ON 子句中引用的列无法更新
。我明白这个错误的原因。但是我们如何重写这段代码呢?不使用光标是否有任何可能性?
I have a code like this
MERGE INTO target_table tgt
USING source_table src
on(tgt.c1=src.c1)
WHEN MATCHED THEN
UPDATE SET tgt.c1=src.c2
I get ORA-38104: Columns referenced in the ON clause cannot be updated
. I understand the reason for this error. But how can we rewrite this code? Is there any possibilities without using cursor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样,外连接意味着
rid
将为 null,从而失败,因此如果您有一个,就会流入语句的WHEN NOT MATCHED
部分How about this, the outer join means the
rid
will be null and thus fail, and so flow into theWHEN NOT MATCHED
part of the statement if you have one您可以利用 ORA-38104 的一些解决方法,这些解决方法似乎一直有效到 Oracle 18c,包括这个,其中您可以将列包装在包含附加虚拟表达式的行值表达式中:
You can exploit some workarounds for ORA-38104, which seem to work up until Oracle 18c, including this one, where you'd wrap your columns in a row value expression that contains an additional dummy expression: