我目前的代码是create table p(px int primary key, createDate date,updateDate date);
insert into p values(1,'23-JUL-15','25-JUL-15');
insert into p values(2, '23/JUN/2015','25-JUL-15');
insert into p values(3, '23/May/2015','25/May/15');
insert into p values(4, '23/April/2015','25/April/2015');
insert into p values(5, '23/March/2015','25/March/2015');
我之前的查询是delete from p where add_months(sysdate, - 3) > p.updateDate;
但是,现在我想使用看起来像if else。
如果updateDate为null,我想使用createDate column.So,现在我使用case语句。我的当前查询是DELETE FROM p WHERE add_months(sysdate, - 3) > case Updatedate when updatedate IS NULL else updateDate end;
但现在我发现了error.Can我使用delete sql query with case statement。
答案 0 :(得分:1)
试试这个
DELETE FROM p WHERE add_months(sysdate, - 3) >
case when updatedate IS NULL then createDate else updateDate end