select nvl(SD_CWAZF,0) into azfze from GC_ZCMX_SD where SD_BH=xmbh 
但是没有数据的时候会报错,请问如何写就不会抱错了。谢谢。

解决方案 »

  1.   

    这个问题,看你要如何处理。一个是事先检测是否有数据。例如select count(*) from .. where 条件。 如果有就查找 Into 进入。
       还有一个是。使用exception.
        exception
      when no_data_found then
        dbms_output.put_line('没有数据!');
      when others then 
        dbms_output.put_line(sqlerrm); 
      

  2.   

    如果是number型,可以利用变相的方法来实现。比如
    select sum(nvl(SD_CWAZF,0)) into azfze from GC_ZCMX_SD where SD_BH=xmbh
      

  3.   

    如 上面说得
    exception
      when no_data_found then
        return false;
      

  4.   

    select nvl((select nvl(SD_CWAZF,0) from GC_ZCMX_SD where SD_BH=xmbh),null) into azfze  from dual ; 搞定,试过很多次了
      

  5.   

    其实 在存储里面使用 select into 时,如果没有得到数据时会触发 异常错误。
    想控制这一点 只要用 
      begin
        select no,name into value1,value2 from emp;
      exception
        when others then
          ........
      end;将 select into 给括上就可以了。还有就是可以考虑用cursor ,用cursor%notfound可以处理。
      

  6.   

    参考下  
    BEGIN
        SELECT OP_USERID
          INTO chrOpUserID
          FROM HU_REMOTE
         WHERE OP_ID = inChrOP_ID;  EXCEPTION
        WHEN  OTHERS THEN
          RAISE UPDATETWO_ERROR_EXCEPTION;
      END;
      

  7.   

    select count(SD_CWAZF) into count_azfze 
    from GC_ZCMX_SD where SD_BH=xmbh ;
    if count_azfze  >0 then 
    select nvl(SD_CWAZF,0) into azfze 
    from GC_ZCMX_SD where SD_BH=xmbh ;
    else
    azfze := 0;
    End if;
      

  8.   

    其实 在存储里面使用 select into 时,如果没有得到数据时会触发 异常错误。
    想控制这一点 只要用 
      begin
        select nvl(SD_CWAZF,0) into azfze from GC_ZCMX_SD where SD_BH=xmbh; 
      exception
        when others then
          ........
      end;将 select into 给括上就可以了。