sql - Best way to upsert from external app -


i have application uses bulk insert put data oracle database table. need change it, upserts it, have hard time finding best solution this. sites suggest using merge insert/update rows, it's effective , simplest solution, examples base on data in table.

what best solution change? using kind of temporary or staging table necessary, or there way skip this?

merge can used constant values well.

however due oracle's lack of support values() row constructor gets bit ugly:

merge the_table using (   select 1 id, 'arthur' name dual ) t on (t.id = the_table.id) when matched     update set name = t.name when not matched     insert (id, name)    values (t.id, t.name); 

this can used multiple rows:

merge the_table using (   select 1 id, 'arthur' name dual -- first row   union   select 2, 'ford' dual -- second row   union   select 3, 'zaphod' dual -- third row ) t on (t.id = the_table.id) when matched     update set name = t.name when not matched     insert (id, name)    values (t.id, t.name); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -