Oracle不支持IF not Exists()解决办法

Oracle不支持IF not Exists()解决办法

方案一:

INSERT  into table1 (column1,column2)
select '123','456' from dual where not exists (select roleid from table1 where column1 = '123');

方案二:

insert when (not exists (SELECT 1 FROM table1 where column1='123' and column2='456')) then
into table1(column1,column2) values ('123','456');

方案三:

INSERT  into table1 (column1,column2) 
select * from
(
    select  decode(count(*),0,'123',null) column1,
           decode(count(*),0,'456',null) column2
    from table1 where column1 = '123'
) where column1 is not null;
posted @ 2022-05-19 13:43  Journey&Flower  阅读(496)  评论(0)    收藏  举报