declarebegin 
   if null != sysdate then
     ................
   else 
    ..................
   end if ;
end ;
好像兩個分支都不會執行~~

解决方案 »

  1.   

    null != sysdate sysdate is not null
      

  2.   

    你什么需求?
    if sysdate is not null then --如果sysdate不为空 
    ...
    else --如果sysdate为空
    ...
    end if;
      

  3.   


    我的意思是想進行兩個日期date1,date2的比較:
    if date1 <> date2 then  --如果date1和date2不相等時
      ..........
    else 
       ..........
    if 但其中一個date1可能是null,如果是null時,就變成了判斷date2是否為null了......
      

  4.   

    用nvl
    nvl(date1,datetime) <> date2 
    如果date1为null 表示两个时间不相等用一个数据库中不存在的时间
    例如:to_date('1111-11-11','yyyy-mm-dd')
    否则用nvl(date1,date2)
      

  5.   

    謝謝你的方法,但我在程式裡可不僅僅是進行一次時間的判斷,而是很多次的,而且date1和date2都有可
    能是null,那不是每次都要用nvl函數,
      

  6.   


    最外层先过滤掉你date1 date2为空的情况
     if date1 is not null  and  date2 is not null then
            if date1 <> date2 then 
             ..........
            else  
               ..........
            end if;
      else
          --返回不相等
      end if;  
      

  7.   

    判断不为null的日期,再进行比较
      

  8.   

    declarebegin 
    if date1 is not null date2 is not null thenif  date1 <> date2 then --如果date1和date2不相等時
      ..........
    else  ---两个不为空 且相等
      ..........
    end if;
    else  ---为空的情况
    .....
    end if; 
      

  9.   

    date1 null      date2 null      => 相等
    date1 null      date2 not null  => 不相等
    date1 not null  date2 null      => 不相等楼主的需求,是这个?
      

  10.   

    最好不要进行null比较,用nvl 转吧。