如果在Oracle中不存在记录,如何插入记录?
发布时间:2021-01-10 05:02:57 所属栏目:站长百科 来源:网络整理
导读:如果记录在Oracle中不存在,如何插入记录?这是我想要做的: IF NOT EXISTS (SELECT * FROM AROH_FAA_AIRPORT WHERE AIRPORT_ABBREVIATION = '0D7') BEGIN insert into AROH_FAA_AIRPORT (FAA_AIRPORT_OID,CITY,FAA_LISTED_AIRPORT_NAME,AIRPORT_ABBREVIATION
如果记录在Oracle中不存在,如何插入记录?这是我想要做的: IF NOT EXISTS (SELECT * FROM AROH_FAA_AIRPORT WHERE AIRPORT_ABBREVIATION = '0D7') BEGIN insert into AROH_FAA_AIRPORT (FAA_AIRPORT_OID,CITY,FAA_LISTED_AIRPORT_NAME,AIRPORT_ABBREVIATION) values(AROH_FAA_AIRPORT_SEQ.nextval,'ADA','0D7') END 解决方法insert into AROH_FAA_AIRPORT (FAA_AIRPORT_OID,AIRPORT_ABBREVIATION) select AROH_FAA_AIRPORT_SEQ.nextval,'0D7') from dual where not exists (select 42 from AROH_FAA_AIRPORT WHERE AIRPORT_ABBREVIATION = '0D7'); 或者,您可以使用MERGE语句: merge into AROH_FAA_AIRPORT a using ( select 'ADA' city,'ADA' as faa_listed_airport_name,'0D7' as as airport_abbreviation from dual ) t ON (t.city = a.city) when not matched then insert (FAA_AIRPORT_OID,AIRPORT_ABBREVIATION) values (AROH_FAA_AIRPORT_SEQ.nextval,t.city,t.faa_listed_airport_name,t.airport_abbreviation); (编辑:上饶站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |