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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

oracle sqlcode 多条,oracle sqlerrm和sqlcode函数

發(fā)布時間:2023/12/31 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle sqlcode 多条,oracle sqlerrm和sqlcode函数 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1.oracle sqlcode函數(shù)

sqlcode函數(shù)用來返回pl/sql執(zhí)行內(nèi)部異常代碼。

語法:sqlcode

oracle sqlerrm函數(shù)

sqlerrm函數(shù)返回指定錯誤代碼的錯誤信息。

語法:SQLERRM [(error_number)]

2.sqlerrm如何使用?

sqlcode和sqlerrm是不能直接在sql語句中使用,必須先將其賦給變量后,才能在sql語句中使用,如下:

dw@dw>declare

2??? v_sqlcode number;

3??? v_sqlcode1 number;

4??? v_sqlerrm varchar2(510);

5? begin

6??? v_sqlcode :=sqlcode;

7??? select v_sqlcode into v_sqlcode1 from dual;

8? end;

9? /

PL/SQL 過程已成功完成。

sqlerrm用得最多的是在pl/sql編程中來捕獲異常的詳細信息,特別是在when others 中使用非有用。

如下:

view plaincopy to clipboardprint?

set serveroutput on

declare

v_count pls_integer;

begin

begin

select 2 into v_count

from dual where 1>2;

exception

when others then

dbms_output.put_line(sqlerrm);

end;

begin

select level into v_count

from dual

connect by level < 3;

end;

end;

/

dw@dw>set serveroutput on

dw@dw>declare

2??? v_count pls_integer;

3? begin

4??? begin

5????? select 2 into v_count

6????? from dual where 1>2;

7???? exception

8?????? when others then

9???????? dbms_output.put_line(sqlerrm);

10??? end;

11??? begin

12????? select level into v_count

13????? from dual

14????? connect by level < 3;

15??? end;

16? end;

17? /

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

declare

*

第 1 行出現(xiàn)錯誤:

ORA-01422: 實際返回的行數(shù)超出請求的行數(shù)

ORA-06512: 在 line 12

3.sqlerrm的最大長度是多少?

其實這個問題很好解答,自定義一個異常,然后用sqlerrm去捕獲即可。

view plaincopy to clipboardprint?

set serveroutput on

begin

raise_application_error(-20001,

'sqlerrm的最大長度是多少' || lpad('我', 10000, '我'));

exception

when others then

dbms_output.put_line(lengthb(sqlerrm));

end;

/

dw@dw>begin

2??? raise_application_error(-20001,

3??????????????????????????? 'sqlerrm的最大長度是多少' || lpad('我', 10000, '我'));

4? exception

5??? when others then

6????? dbms_output.put_line(lengthb(sqlerrm));

7? end;

8? /

510

PL/SQL 過程已成功完成。

dw@dw>

從輸出結(jié)果來看,oracle sqlerrm的最在長度為510個字節(jié)。

4.oracle ora-錯誤信息手冊

從oracle的參考文檔中,可以發(fā)現(xiàn)自定義異常從-20000開始,也就是說,-20000前的數(shù)據(jù)都是oracle內(nèi)部使用的,

可以通過下面這段匿名塊查出oracle所有ora-錯誤信息。

view plaincopy to clipboardprint?

set serveroutput on

exec dbms_output.enable(10000000);

begin

for i in 0..20000 loop

dbms_output.put_line(sqlerrm(-i));

end loop;

end;

/

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

總結(jié)

以上是生活随笔為你收集整理的oracle sqlcode 多条,oracle sqlerrm和sqlcode函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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