creating a logon/logoff auditing system using system-level triggers:
SQL>
SQL> CREATE TABLE logon_audit(
2 user_id VARCHAR2(30),
3 sess_id NUMBER(10),
4 logon_time DATE,
5 logoff_time DATE,
6 host VARCHAR2(20));
Table created.
SQL>
SQL>
SQL> CREATE OR REPLACE TRIGGER logon_audit_trig AFTER LOGON
2 ON DATABASE
3 BEGIN
4 INSERT INTO logon_audit VALUES (user, sys_context('userenv', 'sessionid'),sysdate,null,sys_context('userenv', 'host'));
5 END;
6 /
Trigger created.
SQL> CREATE OR REPLACE TRIGGER logoff_audit_trig BEFORE LOGOFF
2 ON DATABASE
3 BEGIN
4 INSERT INTO logon_audit VALUES (user,sys_context('userenv', 'sessionid'),null,sysdate,sys_context('userenv', 'host'));
5 END;
6 /
Trigger created.
SQL> drop table logon_audit;
Table dropped.
SQL>
SQL>
Related examples in the same category