Skip to content

Instantly share code, notes, and snippets.

@tonfever
Created June 15, 2017 07:22
Show Gist options
  • Save tonfever/a883759fce3dad0f2b243953a04c278f to your computer and use it in GitHub Desktop.
Save tonfever/a883759fce3dad0f2b243953a04c278f to your computer and use it in GitHub Desktop.
Using merge on Oracle example
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