【SQL*Plus】使用11g SQL*Plus的errorlogging選項記錄session級別的錯誤
在Oracle 11g版本的SQL*Plus中提供了一個非常有特色的選項errorlogging。當開啟該選項之後,會話級別的錯誤都會寫入到指定表中,是spool選項的有益補充。spool選項會將所有的輸出資訊都寫入到指定檔案檔案中,這樣會造成檔案內容過於臃腫和繁雜。在使用errorlogging選項後,我們將只關注那些與報錯有關的資訊,可以認為該選項是spool選項的精華抽取。
1.純淨環境準備
保證環境的純淨,我們單獨建立一個普通使用者sec來完成下面的演示。
sys@ora11g> create user sec identified by sec;
User created.
sys@ora11g> grant create session,resource to sec;
Grant succeeded.
sys@ora11g> conn sec/sec
Connected.
sec@ora11g>
2.errorlogging選項的預設值
該引數的預設值是關閉的
sec@ora11g> show errorlogging
errorlogging is OFF
該選項在10g版本中併為提供。
sys@ora10g> show errorlogging
SP2-0735: unknown SHOW option beginning "errorloggi..."
3.啟用errorlogging選項
1)使errorlogging選項生效
sec@ora11g> set errorlogging on
2)檢視errorlogging選項狀態
sec@ora11g> show errorlogging
errorlogging is ON TABLE SEC.SPERRORLOG
在檢視errorlogging選項時,這裡給出了提示:我們將使用表SEC.SPERRORLOG來記錄報錯的有關資訊。
3)獲取表SPERRORLOG的定義
sec@ora11g> desc sperrorlog
Name Null? Type
------------------------- -------- -----------------------
USERNAME VARCHAR2(256)
TIMESTAMP TIMESTAMP(6)
SCRIPT VARCHAR2(1024)
IDENTIFIER VARCHAR2(256)
MESSAGE CLOB
STATEMENT CLOB
注意:該表在未啟用errorlogging選項時是不存在的,同時也不會因為取消errorlogging選項而消失。它是一個真實存在的表。
4)將資訊寫入指定的其他表
如果不指定寫入的表預設會向SPERRORLOG表中寫入,我們有另外一個選擇:將錯誤資訊寫入到我們指定的表中。
(1)這是有前提的,前提就是需要我們實現定義好這個表,表結構要與SPERRORLOG表一樣
sec@ora11g> create table sql_error_log as select * from SPERRORLOG;
Table created.
(2)調整錯誤資訊寫入的表
sec@ora11g> set errorlogging on;
sec@ora11g> show errorlogging
errorlogging is ON TABLE SEC.SPERRORLOG
sec@ora11g> set errorlogging on table sql_error_log
sec@ora11g> show errorlogging
errorlogging is ON TABLE SEC.sql_error_log
OK,此後的錯誤資訊將會向sql_error_log表中寫入。
5)重新連線後該選項會被重新初始化為OFF
sec@ora11g> show errorlogging
errorlogging is ON TABLE SEC.SPERRORLOG
sec@ora11g> conn sec/sec
Connected.
sec@ora11g> show errorlogging
errorlogging is OFF
4.模擬SQL*Plus中的錯誤
sec@ora11g> select * from t;
select * from t
*
ERROR at line 1:
ORA-00942: table or view does not exist
sec@ora11g> @test.sql
select * From t
*
ERROR at line 1:
ORA-00942: table or view does not exist
5.獲取SPERRORLOG表中記錄的錯誤資訊
sec@ora11g> col USERNAME for a8
sec@ora11g> col TIMESTAMP for a30
sec@ora11g> col SCRIPT. for a10
sec@ora11g> col IDENTIFIER for a1
sec@ora11g> col MESSAGE for a40
sec@ora11g> col STATEMENT for a15
sec@ora11g> select * from sperrorlog;
USERNAME TIMESTAMP SCRIPT I MESSAGE STATEMENT
-------- ------------------------------ ---------- - ---------------------------------------- ---------------
SEC 03-DEC-10 07.18.05.000000 PM ORA-00942: table or view does not exist select * from t
SEC 03-DEC-10 07.18.36.000000 PM test.sql ORA-00942: table or view does not exist select * From t
可見,無論是互動式操作過程中出現的錯誤還是在指令碼執行過程中出現的錯誤都被記錄到了SPERRORLOG表中。方便查詢和分析問題。
根據表的定義,MESSAGE欄位僅僅記錄有關ORA、PLA或SP2錯誤的資訊;STATEMENT欄位記錄了導致錯誤對應的語句。
6.官方文件中的參考資訊
“SET ERRORL[OGGING] {ON | OFF} [TABLE [schema.]tablename] [TRUNCATE] [IDENTIFIER identifier]”
這個文件詳實地記錄了errorlogging選項的來龍去脈。
7.小結
與時俱進!相信有了errorlogging選項,我們在除錯指令碼和監控指令碼執行情況時將不再僅僅侷限在spool選項上。提高效率就是珍愛生命。
Good luck.
secooler
10.12.03
-- The End --
1.純淨環境準備
保證環境的純淨,我們單獨建立一個普通使用者sec來完成下面的演示。
sys@ora11g> create user sec identified by sec;
User created.
sys@ora11g> grant create session,resource to sec;
Grant succeeded.
sys@ora11g> conn sec/sec
Connected.
sec@ora11g>
2.errorlogging選項的預設值
該引數的預設值是關閉的
sec@ora11g> show errorlogging
errorlogging is OFF
該選項在10g版本中併為提供。
sys@ora10g> show errorlogging
SP2-0735: unknown SHOW option beginning "errorloggi..."
3.啟用errorlogging選項
1)使errorlogging選項生效
sec@ora11g> set errorlogging on
2)檢視errorlogging選項狀態
sec@ora11g> show errorlogging
errorlogging is ON TABLE SEC.SPERRORLOG
在檢視errorlogging選項時,這裡給出了提示:我們將使用表SEC.SPERRORLOG來記錄報錯的有關資訊。
3)獲取表SPERRORLOG的定義
sec@ora11g> desc sperrorlog
Name Null? Type
------------------------- -------- -----------------------
USERNAME VARCHAR2(256)
TIMESTAMP TIMESTAMP(6)
SCRIPT VARCHAR2(1024)
IDENTIFIER VARCHAR2(256)
MESSAGE CLOB
STATEMENT CLOB
注意:該表在未啟用errorlogging選項時是不存在的,同時也不會因為取消errorlogging選項而消失。它是一個真實存在的表。
4)將資訊寫入指定的其他表
如果不指定寫入的表預設會向SPERRORLOG表中寫入,我們有另外一個選擇:將錯誤資訊寫入到我們指定的表中。
(1)這是有前提的,前提就是需要我們實現定義好這個表,表結構要與SPERRORLOG表一樣
sec@ora11g> create table sql_error_log as select * from SPERRORLOG;
Table created.
(2)調整錯誤資訊寫入的表
sec@ora11g> set errorlogging on;
sec@ora11g> show errorlogging
errorlogging is ON TABLE SEC.SPERRORLOG
sec@ora11g> set errorlogging on table sql_error_log
sec@ora11g> show errorlogging
errorlogging is ON TABLE SEC.sql_error_log
OK,此後的錯誤資訊將會向sql_error_log表中寫入。
5)重新連線後該選項會被重新初始化為OFF
sec@ora11g> show errorlogging
errorlogging is ON TABLE SEC.SPERRORLOG
sec@ora11g> conn sec/sec
Connected.
sec@ora11g> show errorlogging
errorlogging is OFF
4.模擬SQL*Plus中的錯誤
sec@ora11g> select * from t;
select * from t
*
ERROR at line 1:
ORA-00942: table or view does not exist
sec@ora11g> @test.sql
select * From t
*
ERROR at line 1:
ORA-00942: table or view does not exist
5.獲取SPERRORLOG表中記錄的錯誤資訊
sec@ora11g> col USERNAME for a8
sec@ora11g> col TIMESTAMP for a30
sec@ora11g> col SCRIPT. for a10
sec@ora11g> col IDENTIFIER for a1
sec@ora11g> col MESSAGE for a40
sec@ora11g> col STATEMENT for a15
sec@ora11g> select * from sperrorlog;
USERNAME TIMESTAMP SCRIPT I MESSAGE STATEMENT
-------- ------------------------------ ---------- - ---------------------------------------- ---------------
SEC 03-DEC-10 07.18.05.000000 PM ORA-00942: table or view does not exist select * from t
SEC 03-DEC-10 07.18.36.000000 PM test.sql ORA-00942: table or view does not exist select * From t
可見,無論是互動式操作過程中出現的錯誤還是在指令碼執行過程中出現的錯誤都被記錄到了SPERRORLOG表中。方便查詢和分析問題。
根據表的定義,MESSAGE欄位僅僅記錄有關ORA、PLA或SP2錯誤的資訊;STATEMENT欄位記錄了導致錯誤對應的語句。
6.官方文件中的參考資訊
“SET ERRORL[OGGING] {ON | OFF} [TABLE [schema.]tablename] [TRUNCATE] [IDENTIFIER identifier]”
這個文件詳實地記錄了errorlogging選項的來龍去脈。
7.小結
與時俱進!相信有了errorlogging選項,我們在除錯指令碼和監控指令碼執行情況時將不再僅僅侷限在spool選項上。提高效率就是珍愛生命。
Good luck.
secooler
10.12.03
-- The End --
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-682382/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 3.1.1.1 使用 SQL*Plus 啟動資料庫SQL資料庫
- 1.3.2. 關於SQL*PlusSQL
- mybatis plus的學習記錄MyBatis
- SQL*Plus Set引數詳解SQL
- mybatis-plus匯入sql日誌MyBatisSQL
- 1.3.3.5.1. SQL*Plus 連線命令語法SQL
- 1.3.3.4. 步驟3:啟動SQL*PlusSQL
- Mybatis-plus核心功能-自定義SQLMyBatisSQL
- 常見的錯誤 SQL 用法SQL
- mybatis plus 執行sql報錯 CommunicationsException, druid version 1.2.13, jdbcUrl : jdbc:mysql://XXXMyBatisExceptionUIJDBCMySql
- Mybatis-Plus的應用場景及注入SQL原理分析MyBatisSQL
- 3.1.2.2通過 SQL*Plus 使用非預設初始化引數檔案啟動例項SQL
- MsSql資料庫使用SQL plus建立DDL和DML操作方法SQL資料庫
- 1.3.3.1. 關於連線資料庫的SQL*Plus 工具描述資料庫SQL
- mysql的三個sql的monitor選項MySql
- 匯入sql時報日期型別錯誤SQL型別
- 1.3.3. 通過SQL*Plus 連線資料庫SQL資料庫
- 升級提示 執行SQL發生錯誤!錯誤:duplicate column name: picstitleSQL
- 記錄springboot 3.3.5 版本整合 mybatis-plusSpring BootMyBatis
- Mybatis-Plus如何自定義SQL隱碼攻擊器?MyBatisSQL
- [20230329]記錄除錯sql語句遇到的問題.txt除錯SQL
- pbootcms升級提示 執行SQL發生錯誤!錯誤:duplicate column name: picstitlebootSQL
- jsqlparser使用記錄---生成sql語句JSSQL
- Laravel 框架使用 whereIn 查詢 SQL 時資料出錯記錄Laravel框架SQL
- MySQL常見的8種SQL錯誤用法MySql
- SQL:查詢每個類別最新的5條記錄SQL
- Oracle 12c 檢視CDB&PDBs資訊(SQL*PLUS)OracleSQL
- 實戰記錄之SQL server報錯手工注入SQLServer
- 記錄一個sqlSQL
- 記MyBaits-Plus 實現選單的無限層關係AI
- 使用SQL語句去掉重複記錄的兩種方法SQL
- 《C Primer Plus》,362頁勘誤
- 記錄一次錯誤的使用當前時間new Date()引發的錯誤
- SQL未明確定義列錯誤SQL
- 8種常見SQL錯誤用法SQL
- 執行SQL發生錯誤!錯誤:disk I/O errorSQLError
- 編寫 SQL 程式碼時常犯的九個錯誤SQL
- SpringMVC錯誤記錄SpringMVC
- PbootCMS錯誤提示:執行SQL發生錯誤!錯誤:no such column: def1bootSQL