oracle trigger觸發器這servererror

wisdomone1發表於2013-04-18

/************建立用於審計的表t_trace************/
SQL> create table t_trace(username varchar2(10),terminal varchar2(10),ip varchar2(20),time date,action varchar2(100),errormsg varchar2(1000));
 
Table created

/***********建立用於審計系統操作出錯事件的觸發器************/
SQL> create or replace trigger tr_system_error
  2  after servererror on database --關鍵字:servererror,操作一旦出錯即觸發
  3  declare
  4  begin
  5  insert into t_trace values(sys.login_user,sys_context('userenv','terminal'),sys_context('userenv','ip_address'),sysdate,sys.sysevent,dbms_utility.format_error_stack);
  6  end; --觸發器不用顯式commit
  7  /
 
Trigger created

/***********未錯誤操作前的審計表t_trace************/
SQL> select * from t_trace;
 
USERNAME   TERMINAL   IP                   TIME        ACTION                                                                           ERRORMSG
---------- ---------- -------------------- ----------- -------------------------------------------------------------------------------- --------------------------------------------------------------------------------
 
/***********另一會話模擬一個錯誤操作/
SQL> drop table t_xs purge;
 
drop table t_xs purge
 
ORA-00942: table or view does not exist

/***********重新回到原會話錯誤操作已經捕獲並記錄在審計表**************/
SQL> select * from t_trace;
 
USERNAME   TERMINAL   IP                   TIME        ACTION                                                                           ERRORMSG
---------- ---------- -------------------- ----------- -------------------------------------------------------------------------------- --------------------------------------------------------------------------------
TBL_BCK    123-PC     127.0.0.1            2013/4/18 1 SERVERERROR                                                                      ORA-00942: table or view does not exist
 

小結:1,servererror事件與觸發器trigger

         2,sys_context函式

            sys_user函式

            sys_字首的函式

        3,servererror可記錄所有oracle操作同錯的動作

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-758791/,如需轉載,請註明出處,否則將追究法律責任。

相關文章