insert into OPT (email, campaign_id) values('mom@cox.net',100)
where not exists( select * from OPT where (email ="mom@cox.net" and campaign_id =100)) ;
Run Code Online (Sandbox Code Playgroud)
错误报告:SQL错误:ORA-00933:SQL命令未正确结束00933. 00000 - "SQL命令未正确结束"*原因:
*操作:
如果在Oracle中不存在新行,如何插入?
a_h*_*ame 62
insert into OPT (email, campaign_id)
select 'mom@cox.net',100
from dual
where not exists(select *
from OPT
where (email ="mom@cox.net" and campaign_id =100));
Run Code Online (Sandbox Code Playgroud)
小智 8
MERGE INTO OPT
USING
(SELECT 1 "one" FROM dual)
ON
(OPT.email= 'mom@cox.net' and OPT.campaign_id= 100)
WHEN NOT matched THEN
INSERT (email, campaign_id)
VALUES ('mom@cox.net',100)
;
Run Code Online (Sandbox Code Playgroud)
insert into OPT (email, campaign_id)
select 'mom@coxnet' as email, 100 as campaign_id from dual MINUS
select email, campaign_id from OPT;
Run Code Online (Sandbox Code Playgroud)
如果OPT中已存在mom@cox.net/ 100中的记录,MINUS则会从记录中减去此记录,select 'mom@coxnet' as email, 100 as campaign_id from dual并且不会插入任何内容.另一方面,如果没有这样的记录,MINUS则不会减去任何内容,并且将插入值mom@coxnet/ 100.
正如p.marino已经指出的那样,merge对于您的问题来说可能是更好(更正确)的解决方案,因为它专门用于解决您的任务.