+ -
当前位置:首页 → 问答吧 → PL/SQL select不到数据不跳入no_data_found异常

PL/SQL select不到数据不跳入no_data_found异常

时间:2011-09-19

来源:互联网

select A,B,C,D from 表

如果没有搜到数据,则会自动跳入no_data_found异常

但是我希望搜不到数据,可以接下来进入接下来的处理代码。

怎么写呢 把异常no_data_found去掉会跳到更外面的exception,如果不写会弹出未定义的exception。

作者: pjhnew   发布时间: 2011-09-19

select count(*) into cnt from ...

if cnt = 0 then
..没有数据,但不报异常
else
..
end if;

作者: yixilan   发布时间: 2011-09-19

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

作者: lzd_83   发布时间: 2011-09-19

完整语句贴出来

作者: java3344520   发布时间: 2011-09-19

SQL code


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;
/

作者: opps_zhou   发布时间: 2011-09-19

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

...
...

作者: gelyon   发布时间: 2011-09-19

少些了异常
exception WHEN OTHERS then
  NULL;

作者: gelyon   发布时间: 2011-09-19

热门下载

更多