内层的块不捕获,外层也不捕获,则异常被传递到外层后被抛出,同样也不会输出1:
SQL> declare
2 a emp%rowtype;--define a variable
3 begin
4 begin
5 select * into a from emp where empno=0; --此处没有返回行,产生异常
6 --start trap exception
7 exception
8 --when no_data_found then
9 --dbms_output.put_line('no data found!');
10 when too_many_rows then
11 dbms_output.put_line('to many rows found'||sqlcode||','||sqlerrm);
12 --when others then
13 --dbms_output.put_line('others error occur!');
14 end;
15 begin
16 dbms_output.put_line(1);
17 end;
18 end;
19 /
declare
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 5
在块内不捕获异常,在外层捕获,则捕获传递到外层并被捕获,且外层的块不会输出1:
SQL> declare
2 a emp%rowtype;--define a variable
3 begin
4 begin
5 select * into a from emp where empno=0; --此处没有返回行,产生异常
6 --start trap exception
7 exception
8 --when no_data_found then
9 --dbms_output.put_line('no data found');
10 when too_many_rows then
11 dbms_output.put_line('to many rows found!'||sqlcode||','||sqlerrm);
12 --when others then
13 --dbms_output.put_line('others error occur!');
14 end;
15 begin
16 dbms_output.put_line(1);
17 end;
18 exception
19 when no_data_found then
20 dbms_output.put_line('no data found !');
21 end;
22 /
no data found!
PL/SQL procedure successfully completed.
在块内捕获异常,异常不会传递到外层,因此外层的块会输出1:
SQL> declare
2 a emp%rowtype;--define a variable
3 begin
4 begin
5 select * into a from emp where empno=0; --此处没有返回行,产生异常
6 --start trap exception
7 exception
8 when no_data_found then
9 dbms_output.put_line('no data found!');
10 when too_many_rows then
11 dbms_output.put_line('to many rows found!'||sqlcode||','||sqlerrm);
12 --when others then
13 --dbms_output.put_line('others error occur!');
14 end;
15 begin
16 dbms_output.put_line(1);
17 end;
18 end;
19 /
no data found!
1
PL/SQL procedure successfully completed.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10972173/viewspace-709786/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10972173/viewspace-709786/