17,382
社区成员




insert into ABC values('1','2','3') where (select count(*) from ABC where a= ?) < 1
报不能正确结束。-- 如果不用merge into 的话,可以用存储过程:
有一张表ABC,有字段 a,b,c;主键是a,现在我是在插入一条记录前先判断是否已经有相同的主键,如果主键一样则不插入,主键不一样则插入,sql语句怎么写,我写的
-- insert into ABC
values('1','2','3') where (select count(*) from ABC where a= ?) < 1
create or replace procedure abc_inc_proc(
i_a abc.a%type,
i_b abc.b%type,
i_c abc.c%type
)
is
begin
insert into abc(a,b,c)
select i_a as a, i_b as b, i_c as c
from dual a
where not exists (select 1 from abc b where b.a=i_a );
commit;
end;
/
/