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
Post a Comment