oracle 合并:修改多个表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10590325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:49:07  来源:igfitidea点击:

Merge: modifying multiple tables

sqloracle

提问by user1170330

Is it possible to modify several tables, using the mergefunction in Oracle? In each case different operations need to be taken, like:

是否可以使用mergeOracle 中的函数修改多个表?在每种情况下都需要采取不同的操作,例如:

MERGE INTO users tab1
USING(SELECT 1 id, 10 points FROM dual) tab2 
ON(tab1.id = tab2.id ) 
WHEN MATCHED THEN 
   UPDATE SET points = tab2.points 
   UPDATE "abc" = action.status -- another table
WHEN NOT MATCHED THEN 
   INSERT(id, points)  VALUES(tab2.id, tab2.points) 
   UPDATE "def" = action.status -- another table

回答by DCookie

According the the documentation, the simple answer is no. The syntaxsupports one table or view. However, with an updateable view, you could accomplish a multi-table insert/update.

根据文档,简单的答案是否定的。语法支持一个表或视图。但是,使用可更新视图,您可以完成多表插入/更新。

Your example however seems to try to do something else you cannot do. The WHEN MATCHED clause specifies what to UPDATE. You cannot INSERT from this clause. Same thing for the WHEN NOT MATCHED clause - you cannot UPDATE from this clause, only INSERT.

然而,你的例子似乎试图做一些你不能做的事情。WHEN MATCHED 子句指定要更新的内容。您不能从此子句插入。WHEN NOT MATCHED 子句也是如此——你不能从这个子句更新,只能插入。