确定 Oracle SQL MERGE 语句结果

发布于 2024-09-04 11:54:57 字数 599 浏览 4 评论 0原文

跟进这个问题

这个(旧链接的类似版本)有效然而,在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海螺姑娘 2024-09-11 11:54:57

MERGE 语句不发出结果,也不支持 RETURNING 子句。

但是,您可以做的是标记受影响的记录。类似于:

when matched update set .... merge_status = 'U'
when not matched insert ( ...., merge_status, ... ) values ( ...., 'I', .... )

当然,这要求您有一个额外的列来捕获合并状态 - 这并不总是可取的(特别是当您只以短暂的方式需要此信息时,例如验证合并的结果)。

不幸的是,据我所知,这是你能做的最好的事情。

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:

when matched update set .... merge_status = 'U'
when not matched insert ( ...., merge_status, ... ) values ( ...., 'I', .... )

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文