Created
June 15, 2017 07:22
-
-
Save tonfever/a883759fce3dad0f2b243953a04c278f to your computer and use it in GitHub Desktop.
Using merge on Oracle example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MERGE INTO <TABLE_NAME> <ALIAS1> USING | |
( | |
SELECT | |
:COLUMN1 AS COLUMN1 | |
,:COLUMN2 AS COLUMN2 | |
,:COLUMN3 AS COLUMN3 | |
FROM DUAL | |
) <ALIAS2> ON | |
( | |
--- CONDITION | |
<ALIAS2>.COLUMN1 = <ALIAS1>.COLUMN1 | |
AND <ALIAS2>.COLUMN2 = <ALIAS1>.COLUMN2 | |
) | |
WHEN MATCHED THEN | |
--- UPDATE COMMAND | |
UPDATE SET | |
<ALIAS1>.COLUMN3 = <ALIAS2>.COLUMN3 | |
WHEN NOT MATCHED THEN | |
--- INSERT COMMAND | |
INSERT (COLUMN1, COLUMN2, COLUMN3) | |
VALUES (<ALIAS2>.COLUMN1, <ALIAS2>.COLUMN2, <ALIAS2>.COLUMN3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment