Skip to content
Advertisement

ON DUPLICATE KEY UPDATE in oracle or equiv (defining key/column?)

I have the below working insert statement, where I am essentially mapping the column data from an uploaded .csv file through a loop into my VALUES variables below…

All worked fine, except now I am just trying to add a tweak INSERT or UPDATE – if ‘app_id‘ first column, value is found in the uploaded .csv, i.e. duplicate is found – simply update the identified duplicate row..

Based on some research ON DUPLICATE KEY UPDATE is the way to go, but I don’t understand how/where I define the key? – you can see below I tried adding the ON DUPLICATE KEY UPDATE to the end of the query with my variables again, but I’m pretty sure this can’t be correct.

JavaScript

Note: The above was working fine for Insert minus my below attempt adding:

JavaScript

So how can I add ON DUPLICATE KEY UPDATE based off of column app_id correctly – if duplicate app_id value is found in the insert, simply update instead?

Advertisement

Answer

ON DUPLICATE KEY is not a thing in Oracle. The closest equivalent is the MERGE syntax. Here is an example on how to use it for your use case (I reduced the number of columns for the sake of readability):

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement