In Oracle, can I do an “insert or update values into TABLE”
Question
I have a table with two number columns, and a unique constraint over them both. I would like to insert a new pair of values UNLESS the pair already exists. What is the simplest way to do this?
If I do
insert into TABLE values (100,200)
and the pair already exists I get a ORA-00001 error, so I would like to do something like
insert or update into TABLE values (100,200)
Solution
You can use MERGE
OTHER TIPS
You can try something like:
insert into table
select :a, :b from dual
where not exists (select 1 from table where column1 = :a and column2=:b)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow