create table user_audit_log ( user_id varchar2(30 byte), session_id number(8), host varchar2(30 byte), last_program varchar2(48 byte), last_action varchar2(32 byte), last_module varchar2(32 byte), logon_ts timestamp, logoff_ts timestamp, elapsed_seconds number ); create or replace trigger logon_audit_trigger after logon on database begin insert into user_audit_log values( user, sys_context('USERENV','SESSIONID'), sys_context('USERENV','HOST'), null, null, null, current_timestamp, null, null ); end; / create or replace trigger logoff_audit_trigger before logoff on database begin update user_audit_log set last_action = (select action from v$session where sys_context('USERENV','SESSIONID') = audsid) where sys_context('USERENV','SESSIONID') = session_id; update user_audit_log set last_program = (select program from v$session where sys_context('USERENV','SESSIONID') = audsid) where sys_context('USERENV','SESSIONID') = session_id; update user_audit_log set last_module = (select module from v$session where sys_context('USERENV','SESSIONID') = audsid) where sys_context('USERENV','SESSIONID') = session_id; update user_audit_log set logoff_ts = systimestamp where sys_context('USERENV','SESSIONID') = session_id; update user_audit_log set elapsed_seconds = extract(day from (logoff_ts - logon_ts)) * 24*60*60 + extract(hour from (logoff_ts - logon_ts)) * 60*60 + extract(minute from (logoff_ts - logon_ts)) * 60 + extract(second from (logoff_ts - logon_ts)) where sys_context('USERENV','SESSIONID') = session_id; end; /