In Oracle, can I do an "insert or update values into TABLE"
I have 开发者_StackOverflow中文版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)
You can use MERGE
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)
精彩评论