你什么需求? if sysdate is not null then --如果sysdate不为空 ... else --如果sysdate为空 ... end if;
我的意思是想進行兩個日期date1,date2的比較: if date1 <> date2 then --如果date1和date2不相等時 .......... else .......... if 但其中一個date1可能是null,如果是null時,就變成了判斷date2是否為null了......
最外层先过滤掉你date1 date2为空的情况 if date1 is not null and date2 is not null then if date1 <> date2 then .......... else .......... end if; else --返回不相等 end if;
判断不为null的日期,再进行比较
declarebegin if date1 is not null date2 is not null thenif date1 <> date2 then --如果date1和date2不相等時 .......... else ---两个不为空 且相等 .......... end if; else ---为空的情况 ..... end if;
date1 null date2 null => 相等 date1 null date2 not null => 不相等 date1 not null date2 null => 不相等楼主的需求,是这个?
if sysdate is not null then --如果sysdate不为空
...
else --如果sysdate为空
...
end if;
我的意思是想進行兩個日期date1,date2的比較:
if date1 <> date2 then --如果date1和date2不相等時
..........
else
..........
if 但其中一個date1可能是null,如果是null時,就變成了判斷date2是否為null了......
nvl(date1,datetime) <> date2
如果date1为null 表示两个时间不相等用一个数据库中不存在的时间
例如:to_date('1111-11-11','yyyy-mm-dd')
否则用nvl(date1,date2)
能是null,那不是每次都要用nvl函數,
最外层先过滤掉你date1 date2为空的情况
if date1 is not null and date2 is not null then
if date1 <> date2 then
..........
else
..........
end if;
else
--返回不相等
end if;
if date1 is not null date2 is not null thenif date1 <> date2 then --如果date1和date2不相等時
..........
else ---两个不为空 且相等
..........
end if;
else ---为空的情况
.....
end if;
date1 null date2 not null => 不相等
date1 not null date2 null => 不相等楼主的需求,是这个?