判断啊。
if var1 is null then 
  异常处理
end if

解决方案 »

  1.   

    写存储过程时总担心没有记录,into之前先COUNT一次,很烦躁
      

  2.   

    xy185(兔子)
    不是变量的问题吧
    select aaa into var1 from tablea 本身就会出错
      

  3.   

    declare
    var1 tablea.aaa%type;
    begin
    select aaa into var1 from tablea;
    exception
    when others then
    ...
    end;
    /
      

  4.   

    如果记录为空
    select nvl(aaa,0) into var1 from tablea 
    如果没有记录
    begin
    select nvl(aaa,0) into var1 from tablea 
    exception
    when no_data_found then
    ...
    when others then
    ...
    end;
      

  5.   

    select count(*) into v_cou from table;
    if v_cou>0 then
    select field into v_field form table
    end if;
      

  6.   

    if exist(select.....) then
      .........
    else
      ............
      

  7.   

    感觉在这一点上,ORACLE比SQLSERVER 要麻烦N多./././//
      

  8.   

    nvl解决不了找不到符合条件的记录这种情况。
    应该用select max(colname)或者select min(colname) 来解决。
      

  9.   

    用异常处理
    exception when no_data_found then
    var1 := 0;
    如果还和其他语句放在一起。
    最好将该SQL语句独立作成块。
      

  10.   

    写存储过程时总担心没有记录,into之前先COUNT一次,很烦躁
    我也是:)
      

  11.   

    bzszp(www.bzszp.533.net) 你的办法是最好的.^_^