tags:

views:

88

answers:

2

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)
+7  A: 

You can use MERGE

Michael Pakhantsov
+1  A: 

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)
Paulo Guedes