日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

oracle 跳出内层循环,内层程序中发生异常后,不会继续执行外层程序的语句

發(fā)布時間:2025/3/19 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle 跳出内层循环,内层程序中发生异常后,不会继续执行外层程序的语句 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

開發(fā)寫了個存儲過程需要我們審批,發(fā)現(xiàn)子程序中使用了異常處理語句,

通過以下實驗說明這種寫法的問題:

SQL> create table test_number(test_id number);

Table created

Executed in 0.031 seconds

不使用子程序,正常執(zhí)行:

SQL> declare

2 ? ?v_err_mess varchar2(200);

3 ? ?n_count number;

4 ?begin

5 ? ?select count(1) into n_count from test_number;

6 ? ?dbms_output.put_line(n_count);

7 ?exception

8 ? ?when others then

9 ? ? ?v_err_mess:=sqlcode||' '||sqlerrm;

10 ? ? ?dbms_output.put_line(v_err_mess);

11 ?end;

12 ?/

0

PL/SQL procedure successfully completed

不使用子程序,異常執(zhí)行:

SQL> declare

2 ? ?v_err_mess varchar2(200);

3 ? ?n_count number;

4 ?begin

5 ? ?select test_id into n_count from test_number;

6 ? ?dbms_output.put_line(n_count);

7 ?exception

8 ? ?when others then

9 ? ? ?v_err_mess:=sqlcode||' '||sqlerrm;

10 ? ? ?dbms_output.put_line(v_err_mess);

11 ?end;

12 ?/

100 ORA-01403: 未找到任何數(shù)據(jù)

PL/SQL procedure successfully completed

使用子程序,在子程序中進行異常處理:

可以看到,在外層調(diào)用中無法獲取子程序異常處理中的賦值

SQL>

SQL> declare

2 ? ?v_err_mess varchar2(200);

3 ? ?n_count number;

4 ?begin

5 ? ?begin

6 ? ? ?select test_id into n_count from test_number;

7 ? ? ?dbms_output.put_line(n_count);

8 ? ?exception

9 ? ? ?when others then

10 ? ? ? ?v_err_mess:=sqlcode||' '||sqlerrm;

11 ? ? ? ?dbms_output.put_line(v_err_mess);

12 ? ? end;

13

14 ? ? dbms_output.put_line('inner layer values:'||n_count);

15 ?exception

16 ? ?when others then

17 ? ? ?v_err_mess:='out_layer:'||sqlerrm;

18 ? ? ?dbms_output.put_line(v_err_mess);

19 ?end;

20 ?/

100 ORA-01403: 未找到任何數(shù)據(jù)

inner layer values:

PL/SQL procedure successfully completed

使用子程序,在子程序中進行正常處理:

可以看到,在外層調(diào)用中可以獲取子程序中的賦值

SQL> declare

2 ? ?v_err_mess varchar2(200);

3 ? ?n_count number;

4 ?begin

5 ? ?begin

6 ? ? ?select count(1) into n_count from test_number;

7 ? ? ?dbms_output.put_line(n_count);

8 ? ?exception

9 ? ? ?when others then

10 ? ? ? ?v_err_mess:=sqlcode||' '||sqlerrm;

11 ? ? ? ?dbms_output.put_line(v_err_mess);

12 ? ? end;

13

14 ? ? dbms_output.put_line('inner layer values:'||n_count);

15 ?exception

16 ? ?when others then

17 ? ? ?v_err_mess:='out_layer:'||sqlerrm;

18 ? ? ?dbms_output.put_line(v_err_mess);

19 ?end;

20 ?/

0

inner layer values:0

PL/SQL procedure successfully completed

以上實驗

內(nèi)層程序中發(fā)生異常后,不會繼續(xù)執(zhí)行外層程序的語句。

可以在最外層進行異常處理。

來自 “ ITPUB博客 ” ,鏈接:http://blog.itpub.net/26451536/viewspace-1815947/,如需轉(zhuǎn)載,請注明出處,否則將追究法律責任。

與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的oracle 跳出内层循环,内层程序中发生异常后,不会继续执行外层程序的语句的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。