select  A,B,C,D from 表如果没有搜到数据,则会自动跳入no_data_found异常但是我希望搜不到数据,可以接下来进入接下来的处理代码。怎么写呢 把异常no_data_found去掉会跳到更外面的exception,如果不写会弹出未定义的exception。

解决方案 »

  1.   

    select count(*) into cnt from ...if cnt = 0 then
    ..没有数据,但不报异常
    else
    ..
    end if;
      

  2.   

    最好还是在数据块中实现比较好。
    begin
    if ...then
    else
    ..
    exception  when no_data_found
    exits;
    end if;
      

  3.   

    declare
        int_a     number;
    begin
        begin
            select a into int_a from taba where 1 = 2;
        exception
            when no_data_found or to_many_rows then
                null;
        end;
        dbms_output.put_line(int_a);
    end;
    /
      

  4.   

    用匿名块来做,捕获异常不处理就是了,继续做下面的PLSQL块:
    ...
    ...
    begin
      select A,B,C,D into ... from 表;
    exception
      null;
    end;...
    ...
      

  5.   

    少些了异常
    exception WHEN OTHERS then
             NULL;
      

  6.   


    --直接增加个匿名块 很方便
    ...begin
      select A,B,C,D into ... from 表;
    exception
      when no_data_found then
        null;
    end;...
      

  7.   

    exception when no_data_found
    null;
    exception WHEN OTHERS then
    异常
      

  8.   

    这个就可以用啊  declare
        int_a     number;
    begin
        begin
            select t.id into int_a from tttt t where 1 = 2;
        exception
            when no_data_found then
                
                dbms_output.put_line('int_a='||int_a);
        end;
        
        dbms_output.put_line('int_a======='||int_a);
    end;
    /