我的存储过程中有一句
 select dwbm into s_dwbm from dwbm where dwbm = s_bm;的语句,但我发现,如果这条记录取出的值有数据,则以后的存储过程语句能正常执行,如果这句话取不到数据,则存储过程就不向下执行了。请问这是不是oracle的一个bug,还是我写的存储过程有问题,如果有问题该如何解决。

解决方案 »

  1.   

    对,oracle里是这样的,会报找不到数据的错误.
    如果你想继续执行,对单行子查询可以用:select max(dwbm) into s_dwbm from dwbm where dwbm = s_bm;
      

  2.   

    1.
        begin 
            select dwbm into s_dwbm from dwbm where dwbm = s_bm;
        exception when no_data_found then
            ......
        end;     
    2.  
        select count(*) into vcount from dwbm where dwbm = s_bm;
        if vcount>0 then
        ......
      

  3.   

    select nvl(dwbm,'') into s_dwbm from dwbm where dwbm = s_bm;if s_dwbm = '' then
      ......
    else
      ......
    end if;
      

  4.   

    一般条件下,如果为空值,s_dwbm就等于null,而null值不同于'',所以需要注意
      

  5.   

    水清说的第一种方法比较可取,异常处理,可以屏蔽错误发生。
    我说的方法主要是处理不同的结果,但能保证数据继续执行,如果需要异常处理,则如下修改:
    if s_dwbm = '' then
      ......
      Raise_Application_Error(-20000,'数据未找到');
    else
      ......
    end if;