我有一个包含两个数字列的表,并且对它们都有一个唯一约束。我想插入一对新的值,除非这对已经存在。最简单的方法是什么?
如果我做
insert into TABLE values (100,200)
并且这对已经存在我收到 ORA-00001 错误,所以我想做类似的事情
insert or update into TABLE values (100,200)
您可以使用合并
您可以尝试以下方法:
insert into table
select :a, :b from dual
where not exists (select 1 from table where column1 = :a and column2=:b)