select decode(col1,null,'null',col1) into v_col1 ...;
if(v_col1='null') then
  --do something;
else
  --do something;
end if;

解决方案 »

  1.   

    TO  jiezhi(浪子) :select decode(col1,null,'null',col1) into v_col1 ...;
    decode()中的东西是什么意思?怎么还有'null'?
      

  2.   

    關于decode:
    http://gigabase.idi.ntnu.no/oradoc/server.901/a90125/functions33.htm#1017439
    'null'只是一個字符串罷了,你可以換成別的。比如'data not found'什么的。
    這么處理是因為如果select ... into 沒有select到任何數據的話會出錯,所以總是讓它select出值來,這樣就不出錯了。你好象是用ms sql的吧?
      

  3.   

    to jiezhi(浪子) :
    我用的是pl/sql
    问题是要select很多字段,字段不为空,
    sum每一个字段
      

  4.   

    SQL> set serveroutput on
    SQL> declare
      2  t_col2 varchar2(20);
      3  begin
      4  select nvl(aaa,'111') into t_col2 from tn where 1=2;
      5  exception when no_data_found then
      6  t_col2 := 'is null';
      7  DBMS_OUTPUT.PUT_LINE('col2 is:'||t_col2);
      8  end;
      9  /
    col2 is:is nullPL/SQL 过程已成功完成。SQL>
      

  5.   

    declare
    v1 varchar2(10);
    v2 varchar2(10);
    ...
    begin
    select sum(col1),sum(col2),... into v1,v2,... from tn where ...;
    exception
    when other then
    v1:=...;
    v2:=...;
    end;
    /