Database Logoff Trigger SQL

tolilong發表於2015-08-24

create or replace trigger logoff_tri
before logoff on database
declare
logoff_sid varchar2(50);
logoff_datetime  date :=sysdate;
begin
  select sid into logoff_sid from v$mystat where rownum<2;
  insert into session_event_history
  select s.SID,s.SERIAL#,s.USERNAME,s.OSUSER,s.PADDR,s.PROCESS,s.LOGON_TIME,s.TYPE,se.EVENT,se.TOTAL_WAITS,se.TOTAL_TIMEOUTS,se.TIME_WAITED,se.AVERAGE_WAIT,se.MAX_WAIT,sysdate datetime
  from v$session_event se,v$session s
  where se.SID=s.SID and s.sid=(select distinct sid from v$mystat where rownum<2);

  insert into sesstat_history
  select se.USERNAME,se.OSUSER,se.SID,se.SERIAL#,se.PADDR,se.PROCESS,se.LOGON_TIME,sa.STATISTIC#,st.NAME,sa.VALUE,sysdate datetime from
  v$sesstat sa,v$statname st,v$session se
  where sa.STATISTIC#=st.STATISTIC# and sa.SID=se.SID and sa.VALUE<>0
  and se.sid=(select distinct sid from v$mystat where rownum<2);
commit;
end;

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

相關文章