Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge: modifying multiple tables

Tags:

sql

oracle

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

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
like image 490
Evgenij Reznik Avatar asked May 14 '12 20:05

Evgenij Reznik


1 Answers

According the the documentation, the simple answer is no. The syntax supports 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.

like image 126
DCookie Avatar answered Sep 28 '22 04:09

DCookie