好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > Oracle查詢sql錯誤信息的控制和定位

Oracle查詢sql錯誤信息的控制和定位

熱門標簽:貴陽電話外呼系統哪家好 400電話是不是免費申請 安陽外呼系統免費 分布式呼叫中心 呼倫貝爾智能手機地圖標注 濟南地圖標注公司 南寧人工智能電銷機器人費用 海南400電話哪里辦理 圖像地圖標注

在sqlplus中執行的sql出錯之后應該如何處理和對應,多行sql語句或者存儲過程的信息如何進行錯誤定位,這篇文章將結合實例進行簡單地說明。

環境準備

使用Oracle的精簡版創建docker方式的demo環境,詳細可參看:

  • https://www.jb51.net/article/153533.htm

如何進行錯誤定位

場景:

假如有3行insert的sql語句,中間一行出錯之后,后續繼續執行的情況下,如何定位到第二行?

dbms_utility.format_error_backtrace

通過使用dbms_utility.format_error_backtrace可以得到ERROR at line xxx:的信息,這對我們較為有用,我們接下來進行確認

oracle@e871d42341c0:~$ sqlplus system/abcd1234@XE EOF
> SET SERVEROUTPUT ON
> desc student
> delete from student;
> select * from student;
> insert into student values (1001, 'liumiaocn');
> insert into student values (1001, 'liumiao');
> insert into student values (1003, 'michael');
> select * from student;
> commit;
> exec dbms_output.put_line(dbms_utility.format_error_backtrace);
> EOF
SQL*Plus: Release 11.2.0.2.0 Production on Sun Oct 21 13:06:07 2018
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> SQL> Name    Null?  Type
 ----------------------------------------- -------- ----------------------------
 STUID    NOT NULL NUMBER(4)
 STUNAME     VARCHAR2(50)
SQL> 
2 rows deleted.
SQL> 
no rows selected
SQL> 
1 row created.
SQL> insert into student values (1001, 'liumiao')
*
ERROR at line 1:
ORA-00001: unique constraint (SYSTEM.SYS_C007024) violated
SQL> 
1 row created.
SQL> 
   STUID STUNAME
---------- --------------------------------------------------
   1001 liumiaocn
   1003 michael
SQL> 
Commit complete.
SQL> 
PL/SQL procedure successfully completed.
SQL> Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
oracle@e871d42341c0:~$ 

可以看到,報錯的時候提示了行號,但是行號是1,這是因為這種寫法以一行為單位,自然是如此,如果是單個多行的存儲過程,將會更加清晰。

ERROR at line 1:
ORA-00001: unique constraint (SYSTEM.SYS_C007024) violated

所以我們將這個例子進行改造,三行insert的sql放到文件之中,然后在使用dbms_utility.format_error_backtrace來進行確認

oracle@e871d42341c0:~$ cat /tmp/sqltest1.sql 
desc student
delete from student;
select * from student;
insert into student values (1001, 'liumiaocn');
insert into student values (1001, 'liumiao');
insert into student values (1003, 'michael');
select * from student;
commit;
oracle@e871d42341c0:~$

然后在嘗試一下是否能夠確認行號,會發現仍然不能精確定位:

oracle@e871d42341c0:~$ sqlplus system/abcd1234@XE EOF
> SET SERVEROUTPUT ON
> @/tmp/sqltest1.sql
> exec dbms_output.put_line(dbms_utility.format_error_backtrace);
> EOF
SQL*Plus: Release 11.2.0.2.0 Production on Sun Oct 21 13:08:27 2018
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> SQL> Name    Null?  Type
 ----------------------------------------- -------- ----------------------------
 STUID    NOT NULL NUMBER(4)
 STUNAME     VARCHAR2(50)
2 rows deleted.
no rows selected
1 row created.
insert into student values (1001, 'liumiao')
*
ERROR at line 1:
ORA-00001: unique constraint (SYSTEM.SYS_C007024) violated
1 row created.
   STUID STUNAME
---------- --------------------------------------------------
   1001 liumiaocn
   1003 michael
Commit complete.
SQL> 
PL/SQL procedure successfully completed.
SQL> Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
oracle@e871d42341c0:~$ 

因為dbms_utility.format_error_backtrace更多的場景是在于存儲過程的錯誤定位,接下來我們使用一個簡單的存儲過程例子來進行確認錯誤行號定位, 先看一個正常的存儲過程,把上面的內容稍微修改一下:

oracle@e871d42341c0:~$ cat /tmp/addstudent.sql 
create or replace PROCEDURE addstudents
IS
student_count number;
BEGIN
delete from student;
select count(*) into student_count from student;
dbms_output.put('sql set count before :');
dbms_output.put_line(student_count);
insert into student values (1001, 'liumiaocn');
insert into student values (1002, 'liumiao');
insert into student values (1003, 'michael');
select count(*) into student_count from student;
dbms_output.put('sql set count after :');
dbms_output.put_line(student_count);
END;
/
exec addstudents();
oracle@e871d42341c0:~$

結果執行信息如下

oracle@e871d42341c0:~$ sqlplus system/liumiao123 EOF
set serveroutput on;
@/tmp/addstudent.sql 
EOF
SQL*Plus: Release 11.2.0.2.0 Production on Mon Oct 22 04:42:11 2018
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> SQL> 
Procedure created.
sql set count before :0
sql set count after :3
PL/SQL procedure successfully completed.
SQL> Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
oracle@e871d42341c0:~$ 

接下來我們修改一下內容,使得第二行主鍵重復

oracle@e871d42341c0:~$ cat /tmp/addstudent.sql
create or replace PROCEDURE addstudents
IS
student_count number;
BEGIN
delete from student;
select count(*) into student_count from student;
dbms_output.put('sql set count before :');
dbms_output.put_line(student_count);
insert into student values (1001, 'liumiaocn');
insert into student values (1001, 'liumiao');
insert into student values (1003, 'michael');
select count(*) into student_count from student;
dbms_output.put('sql set count after :');
dbms_output.put_line(student_count);
END;
/
exec addstudents();
oracle@e871d42341c0:~$ 

再次執行,自然會出錯,但是可以看到,正確報出了所在行數,這是procedure的機制提示的信息

oracle@e871d42341c0:~$ sqlplus system/liumiao123 EOF
set serveroutput on;
@/tmp/addstudent.sql 
EOF
SQL*Plus: Release 11.2.0.2.0 Production on Mon Oct 22 04:44:25 2018
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> SQL> 
Procedure created.
sql set count before :0
BEGIN addstudents(); END;
*
ERROR at line 1:
ORA-00001: unique constraint (SYSTEM.SYS_C007024) violated
ORA-06512: at "SYSTEM.ADDSTUDENTS", line 10
ORA-06512: at line 1
SQL> Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
oracle@e871d42341c0:~$

可以看到,ORA-06512: at “SYSTEM.ADDSTUDENTS”, line 10的信息就是我們期待的信息,提示出在這個存儲過程的第10行執行出現問題,而實際可以使用dbms_utility.format_error_backtrace結合exception給出更為清晰地方式,比如:

oracle@e871d42341c0:~$ cat /tmp/addstudent.sql 
create or replace PROCEDURE addstudents
IS
student_count number;
BEGIN
delete from student;
select count(*) into student_count from student;
dbms_output.put('sql set count before :');
dbms_output.put_line(student_count);
insert into student values (1001, 'liumiaocn');
insert into student values (1001, 'liumiao');
insert into student values (1003, 'michael');
select count(*) into student_count from student;
dbms_output.put('sql set count after :');
dbms_output.put_line(student_count);
exception
when others then
dbms_output.put('exception happend with line info : ');
dbms_output.put_line(dbms_utility.format_error_backtrace);
END;
/
exec addstudents();
oracle@e871d42341c0:~$

執行結果確認:

oracle@e871d42341c0:~$ sqlplus system/liumiao123 EOF
set serveroutput on;
@/tmp/addstudent.sql 
EOF
SQL*Plus: Release 11.2.0.2.0 Production on Mon Oct 22 04:49:27 2018
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> SQL> 
Procedure created.
sql set count before :0
exception happend with line info : ORA-06512: at "SYSTEM.ADDSTUDENTS", line 10
PL/SQL procedure successfully completed.
SQL> Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
oracle@e871d42341c0:~$ 

這樣則可以看出能夠比較清晰地進行錯誤的定位了,但是由于功能受限,所以實際使用場景仍然較為有限,但是定位存儲過程的信息則可以使用dbms_utility.format_error_backtrace等進行確認。

小結

多行sql執行定位可以考慮拆成單行來確認,而存儲過程則可結合format_error_backtrace等進行確認以提供問題出現的所在行號。

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關內容請查看下面相關鏈接

您可能感興趣的文章:
  • Oracle 11g收集多列統計信息詳解
  • Oracle cloud control 12c的啟動、關閉及獲取安裝信息的方法
  • Oracle 查詢表信息獲取表字段及字段注釋
  • oracle獲取當前用戶表、字段等詳細信息SQL
  • Oracle 11g自動診斷信息庫(Automatic Diagnostic Repository,ADR)概述
  • ORACLE查看當前賬號的相關信息

標簽:焦作 滁州 遼源 涼山 南充 郴州 合肥 許昌

巨人網絡通訊聲明:本文標題《Oracle查詢sql錯誤信息的控制和定位》,本文關鍵詞  Oracle,查詢,sql,錯誤,信息,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Oracle查詢sql錯誤信息的控制和定位》相關的同類信息!
  • 本頁收集關于Oracle查詢sql錯誤信息的控制和定位的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 色吊丝在线观看国产| 好色tv黄色在线看| 国拍在线精品视频免费观看| 日韩精品一线二线三线| 漂亮的秘书伦理HD| 亚洲伦理视频| 极品尤物欧美爆乳巨大A片| 国产无套普通话对白| 日日拍夜夜嗷嗷叫国产| 精品无码秘?人妻一区二蜜桃| 91麻豆国产自产观看在线| 69xxxxtube日本免费| 猫女的诅咒追剧看| 白袜体育生臭脚gay奴粗口网站| 超清纯白嫩大学生无码网页| 啊轻点灬大ji巴太粗太长了网站 | 91人成网站色www免费| 911国产精品| 精品夜夜澡人妻无码AV| 女人私密紧致手术视频| 一级全黄色| 一级毛片一级毛片免费毛片| 国产精品美女在线观看直播| 玄女心经电影完整版在线观看 | 老扒与淑蓉夜夜春宵| 漂流教室在线观看| 全黄H全肉短篇禁乱np第一次| 美女高潮图| 美女把尿口露出| 工本口子库入口免费密码在哪 | 爽歪歪亚洲日本电影| 综合aⅴ| 女同性恋电影完整版免费版在线观看| 精品国产精品三级精品AV网址 | jizz 大全欧美| 国产三级精品在线| 少爷菊眼乖乖高C扇肿菊眼| 中文字幕人妻一区二区在线视频| 亚洲一区中文字幕在线观看| 打扑克带劲的视频| 污到湿的小说|