日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

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

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

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

SQL> create table test_number(test_id number);

Table created

Executed in 0.031 seconds

不使用子程序,正常執行:

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

不使用子程序,異常執行:

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: 未找到任何數據

PL/SQL procedure successfully completed

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

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

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: 未找到任何數據

inner layer values:

PL/SQL procedure successfully completed

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

可以看到,在外層調用中可以獲取子程序中的賦值

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

以上實驗

內層程序中發生異常后,不會繼續執行外層程序的語句。

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

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

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

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。