[20170410]11G ora_sql_txt是否有效.txt
[20170410]11G ora_sql_txt是否有效.txt
--連結問的問題: http://www.itpub.net/thread-2086256-1-1.html
--我寫的測試指令碼,自己測試看看:
1.環境:
SYS@test> @ ver1
PORT_STRING VERSION BANNER CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0 12.1.0.1.0 Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production 0
CREATE TABLE SYS.ERROR_LOG
(
IP_ADDRESS VARCHAR2(30 BYTE),
USERNAME VARCHAR2(30 BYTE),
INSTANCE_NUMBER NUMBER(2),
THEDATE DATE,
ERRORMSG VARCHAR2(4000 BYTE),
OTHERMSG VARCHAR2(4000 BYTE),
SQLSTMT VARCHAR2(4000 BYTE)
)
TABLESPACE USERS;
CREATE OR REPLACE TRIGGER SYS.LOG_ERRORS
AFTER SERVERERROR ON DATABASE
DECLARE
sqltext ora_name_list_t;
errmsg VARCHAR2 (4000) := NULL;
errstmt VARCHAR2 (4000) := NULL;
errothermsg VARCHAR2 (4000) := NULL;
BEGIN
IF ( is_servererror (942))
THEN
FOR DEPTH IN 1 .. ora_server_error_depth
LOOP
errmsg := errmsg || ora_server_error_msg (DEPTH);
END LOOP;
FOR cntr IN 1 .. ora_sql_txt (sqltext)
LOOP
errstmt := errstmt || sqltext (cntr);
END LOOP;
SELECT 'sid:' || SID || ' SERIAL#: ' || serial# || ' machina:' || machine || ' program:' || program || ' module:'
|| module
INTO errothermsg
FROM v$session
WHERE SID = (SELECT SID
FROM v$mystat
WHERE ROWNUM = 1);
INSERT INTO error_log
(ip_address, username, instance_number, thedate, errormsg, othermsg,
sqlstmt
)
VALUES (SYS_CONTEXT ('USERENV', 'IP_ADDRESS'), ora_login_user, ora_instance_num, SYSDATE, errmsg, errothermsg,
errstmt
);
END IF;
END;
/
2.測試:
SYS@test> SYS@test> select * from aaaaaaaaa;
select * from aaaaaaaaa
*
ERROR at line 1:
ORA-00942: table or view does not exist
SYS@test>select * from error_log;
Record View
As of: 2017/4/10 20:39:19
IP_ADDRESS:
USERNAME: SYS
INSTANCE_NUMBER: 1
THEDATE: 2017/4/10 20:35:55
ERRORMSG: ORA-00942: table or view does not exist
OTHERMSG: sid:242 SERIAL#: 3 machina:WORKGROUP\XXXX program:sqlplus.exe module:sqlplus.exe
SQLSTMT: select * from aaaaaaaaa
--//不是ok的嗎?我使用12c.
--連結問的問題: http://www.itpub.net/thread-2086256-1-1.html
--我寫的測試指令碼,自己測試看看:
1.環境:
SYS@test> @ ver1
PORT_STRING VERSION BANNER CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0 12.1.0.1.0 Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production 0
CREATE TABLE SYS.ERROR_LOG
(
IP_ADDRESS VARCHAR2(30 BYTE),
USERNAME VARCHAR2(30 BYTE),
INSTANCE_NUMBER NUMBER(2),
THEDATE DATE,
ERRORMSG VARCHAR2(4000 BYTE),
OTHERMSG VARCHAR2(4000 BYTE),
SQLSTMT VARCHAR2(4000 BYTE)
)
TABLESPACE USERS;
CREATE OR REPLACE TRIGGER SYS.LOG_ERRORS
AFTER SERVERERROR ON DATABASE
DECLARE
sqltext ora_name_list_t;
errmsg VARCHAR2 (4000) := NULL;
errstmt VARCHAR2 (4000) := NULL;
errothermsg VARCHAR2 (4000) := NULL;
BEGIN
IF ( is_servererror (942))
THEN
FOR DEPTH IN 1 .. ora_server_error_depth
LOOP
errmsg := errmsg || ora_server_error_msg (DEPTH);
END LOOP;
FOR cntr IN 1 .. ora_sql_txt (sqltext)
LOOP
errstmt := errstmt || sqltext (cntr);
END LOOP;
SELECT 'sid:' || SID || ' SERIAL#: ' || serial# || ' machina:' || machine || ' program:' || program || ' module:'
|| module
INTO errothermsg
FROM v$session
WHERE SID = (SELECT SID
FROM v$mystat
WHERE ROWNUM = 1);
INSERT INTO error_log
(ip_address, username, instance_number, thedate, errormsg, othermsg,
sqlstmt
)
VALUES (SYS_CONTEXT ('USERENV', 'IP_ADDRESS'), ora_login_user, ora_instance_num, SYSDATE, errmsg, errothermsg,
errstmt
);
END IF;
END;
/
2.測試:
SYS@test> SYS@test> select * from aaaaaaaaa;
select * from aaaaaaaaa
*
ERROR at line 1:
ORA-00942: table or view does not exist
SYS@test>select * from error_log;
Record View
As of: 2017/4/10 20:39:19
IP_ADDRESS:
USERNAME: SYS
INSTANCE_NUMBER: 1
THEDATE: 2017/4/10 20:35:55
ERRORMSG: ORA-00942: table or view does not exist
OTHERMSG: sid:242 SERIAL#: 3 machina:WORKGROUP\XXXX program:sqlplus.exe module:sqlplus.exe
SQLSTMT: select * from aaaaaaaaa
--//不是ok的嗎?我使用12c.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2136986/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 分析索引是否有效索引
- 檢查連線是否有效
- php檢查某個日期是否有效PHP
- 如何判斷一個連結地址是否有效
- oracle中檢視某個表的索引是否有效Oracle索引
- 演算法題:判斷括號字串是否有效演算法字串
- vue.js判斷網址引數是否有效Vue.js
- 行內元素的padding和margin是否有效padding
- C#使用HTTP頭檢測網路資源是否有效C#HTTP
- 【Oracle】修改indexed 欄位是否影響索引的有效性OracleIndex索引
- Oracle 11g 檢查 RMAN 備份的有效性Oracle
- 用jquery驗證使用者名稱是否有效或重複jQuery
- 如何有效檢測APP是否安全?這五種方法很常見!APP
- [20170207]11G mmon程式死掉.txt
- [20180627]測試bbed是否支援管道命令.txt
- 如何有效判斷網站是否被攻擊?這幾點要牢記!網站
- 企業衡量內容營銷是否有效的5個關鍵指標指標
- [20190306]11g health monitor.txt
- [20170619]11G expand sql text.txtSQL
- [20130730]11G的DRCP特性.txt
- [20140909]oracle cluster index (11g).txtOracleIndex
- 11g 是否有解決clustering_factor 高的問題
- 文字獲取和搜尋引擎如何評估一個演算法是否有效演算法
- [20220329]是否開發寫錯sql語句.txtSQL
- [20171201]nc快速判斷埠是否開啟.txt
- [20120830]11G SPM的學習6.txt--第3方優化.txt優化
- 驗證oracle 11g資料庫的RMAN備份的有效性Oracle資料庫
- [20161130]11g跟蹤檔案位置.txt
- [20170824]11G備庫啟用DRCP連線.txt
- [20170518]11G審計日誌清除3.txt
- [20170207]11G審計日誌清除.txt
- [20121004]11G下編譯bbed.txt編譯
- 10g 11g 檢視是否DISABLE CRS和10g 11g LOCAL listener的區別
- [20190211]簡單測試埠是否開啟.txt
- [20171204]nc快速判斷埠是否開啟2.txt
- [20180928]如何能在11g下執行.txt
- [20170502]11G查詢隱含引數檢視.txt
- [20170620]11G 12c expand sql text.txtSQL