Skip to content

Instantly share code, notes, and snippets.

@baybatu
Last active April 27, 2016 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baybatu/f59b4e70d1cb57417323 to your computer and use it in GitHub Desktop.
Save baybatu/f59b4e70d1cb57417323 to your computer and use it in GitHub Desktop.
Upsert example in PL/SQL
-- Insert entity into MY_TABLE table using 'entity_id' and 'name' fields if not exists.
-- Otherwise, update row's 'name' field.
MERGE INTO MY_TABLE TBL USING dual ON (TBL.entity_id = ?)
WHEN NOT MATCHED THEN INSERT (entitiy_id, name) VALUES (?, ?)
WHEN MATCHED THEN UPDATE SET TBL.name = ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment