确定 Oracle SQL MERGE 语句结果
跟进这个问题
这个(旧链接的类似版本)有效然而,在 SQL Server 2008 中,Oracle 给我带来了麻烦:
MERGE INTO wdm_test
USING ( select '10000000000000000000000000000000' Guid from DUAL ) val
ON ( wdm_test.Guid = val.Guid )
WHEN MATCHED THEN UPDATE SET test_column = null
WHEN NOT MATCHED THEN
INSERT (Guid, test_column)
VALUES ('10000000000000000000000000000000', null)
OUTPUT $action;
SQL Error: ORA-00933: SQL command not properly ended
Oracle 不支持 OUTPUT $action; 吗?如果没有,还有其他选择吗?
Follow up to this question
This (similar version from old link) works in SQL Server 2008, however, Oracle is giving me trouble:
MERGE INTO wdm_test
USING ( select '10000000000000000000000000000000' Guid from DUAL ) val
ON ( wdm_test.Guid = val.Guid )
WHEN MATCHED THEN UPDATE SET test_column = null
WHEN NOT MATCHED THEN
INSERT (Guid, test_column)
VALUES ('10000000000000000000000000000000', null)
OUTPUT $action;
SQL Error: ORA-00933: SQL command not properly ended
Does Oracle not support OUTPUT $action;
? If not, is there an alternative?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MERGE 语句不发出结果,也不支持
RETURNING
子句。但是,您可以做的是标记受影响的记录。类似于:
当然,这要求您有一个额外的列来捕获合并状态 - 这并不总是可取的(特别是当您只以短暂的方式需要此信息时,例如验证合并的结果)。
不幸的是,据我所知,这是你能做的最好的事情。
The MERGE statement does not emit the results, nor does it support the
RETURNING
clause.However, what you could do is flag the records that are affected. Something like:
This, of course, requires that you have an additional column to capture the merge status - which isn't always desirable (especially when you only need this information in a transient manner, say to verify the results of the merge).
Unfortunately, to my knowledge, this is the best you can do.