Oracle 9i (PL/SQL) 中的条件插入/更新
我正在尝试根据某些条件构建一个查询来插入或更新/删除一行。我试图使用 MERGE 子句,但它有一些限制,不允许我更改某些字段。
这是代码:
MERGE INTO CADUSUNET t
USING (select 'FELIPE' as nomusunet from cademp where rownum = 1) v --generate the column and the value to compare
ON (t.nomusunet = v.nomusunet)
WHEN MATCHED THEN
UPDATE SET t.nomusunet = 'FELIPE BUENO' --I can't update a column that is referenced in the ON condition clause
WHEN NOT MATCHED THEN
INSERT (nomusunet) VALUES ('FELIPE BUENO')
有办法做到这一点吗?
I am trying to build a query to INSERT or UPDATE / DELETE a row depending on some conditions. I was trying to use the MERGE clause but it has some restrictions that doesn't let me change some fields.
Here is the code:
MERGE INTO CADUSUNET t
USING (select 'FELIPE' as nomusunet from cademp where rownum = 1) v --generate the column and the value to compare
ON (t.nomusunet = v.nomusunet)
WHEN MATCHED THEN
UPDATE SET t.nomusunet = 'FELIPE BUENO' --I can't update a column that is referenced in the ON condition clause
WHEN NOT MATCHED THEN
INSERT (nomusunet) VALUES ('FELIPE BUENO')
Is there a way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以这样做:
You could do this: