忘了說了,用nvl(qty,0),執行是可以執行,但在程序中就能不過了,應該還是oracle發生了錯誤。但怎麼解決呢?

解决方案 »

  1.   

    begin
        select qty into b1...;
        exception when no_data_found then
          ...;
    end;
      

  2.   

    sql语句里用nvl(qty,0),是可以处理记录的空值,但前提是找到记录
    如果语句返回的结果是没有找到记录时,那就谈不上了。
    begin
        select nvl(qty,0) into b1 from aaa where ...;
        exception when no_data_found then
          raise_application_error( -20451, '无记录: '|| SQLERRM ) 
        end;
      

  3.   

    loop
    fetch xxx into a1begin
    select qty into b1
    from ...
    where ....
    exception when no_data_found then
    b1:=0;
    end;if  a1=b1 then ....end loop正是楼上几位所说的.
      

  4.   

    select qty into nvl(b1,0)
    from ...
    where ....
    或者
    select qty into b1
    from ...
    where .... exception 
       when others then
        bl:=0;
      

  5.   

    找不着值和值为null是两个概念。
    在过程中找不着值是要用when no_data_found 来捕获的,它不等于值为null。
    而对于找到了值且值为null可以用nvl函数。