0

我有一个包含两个数字列的表,并且对它们都有一个唯一约束。我想插入一对新的值,除非这对已经存在。最简单的方法是什么?

如果我做

insert into TABLE values (100,200) 

并且这对已经存在我收到 ORA-00001 错误,所以我想做类似的事情

insert or update into TABLE values (100,200)
4

2 回答 2

7

您可以使用合并

于 2010-10-06T13:50:46.767 回答
1

您可以尝试以下方法:

insert into table
select :a, :b from dual
where not exists (select 1 from table where column1 = :a and column2=:b)
于 2010-10-06T13:59:36.647 回答