我在存储过程中要从表中查询记录,如果按一组条件没有找到的话,换另外一组条件查找,可是存储过程中如果select语句没有查到记录的话,会出发异常,这样我的下一个查询语句只能写到异常处理里面了,而我有好几组这样的条件,这样写起来很麻烦而且很不好看,请问怎样可以让存储过程忽略这样异常,而让我自己判断有没有查询到记录呢?谢谢!

解决方案 »

  1.   

    create or replace procedure xxx is 
      .....
    begin  begin
        select statement    exception statement    return;
      end;  ...  begin
        select statement    exception statement    return;
      end;        final statements
    end;
      

  2.   

    不行啊,return就直接跳出程序了。
      

  3.   

    我一般的做法是先判断select能不能取到记录。不能的话,跳转到下面的语句。
    select count(*) into li_count from ****
    if li_count>0 then
      /*正常往下*/
    else
       select count(*) into **********
    end if;我也想知道有没有更好的方法。
      

  4.   

    把你的code贴出来看有没有好的解决方法,问题有点笼统
      

  5.   

    SELECT * INTO jl  FROM table  WHERE 条件1 AND ROWNUM = 1;若查询到记录,则处理记录,若没有,则用条件2查找SELECT * INTO jl  FROM table  WHERE 条件2 AND ROWNUM = 1;有希望查不到记录的时候不要抛出异常,跳出程序,能让我判断有没有查到,然后决定是否要用条件2继续查找,因为有三组条件,若用异常比较麻烦,而且很不好看。
      

  6.   

    create or replace procedure xxx is 
      .....
    begin  begin
        select statement    exception statement  end;  ...  begin
        select statement    exception statement  end;        final statements
    end;
      

  7.   

    那种方法是可以,不过应该比较浪费性能啊,CodeMagic能不能详细说一下你的方法呢?
      

  8.   


      begin
        select statement    exception statement  end;加了begin end的目的是防止嵌套层数过多,代码不用缩进,好看些