---Create log table records user logon information
CREATE TABLE User_log
(
user_id VARCHAR2 (30),
session_id Number (10),
HOST_NAME VARCHAR2 (30),
Last_module VARCHAR2 (30),
Logon_day DATE,
Logoff_day DATE,
Elapsed_minutes Number (10)
);
--Create a trigger after the user logs in to count the user's login information:
Create or Replace Trigger Logon_trigger
After logon on database
Begin
INSERT INTO User_log
Values
User
Sys_context (' Userenv ', ' SessionID '),
Sys_context (' Userenv ', ' host '),
Null
Sysdate,
Null
Null
);
End
SELECT * from User_log;
--Create a trigger before the user log out to count the information when the user logged out:
Create or Replace Trigger Logoff_trigger
Before logoff on database
Begin
Update User_log
Set last_module =
(SELECT module
From V$session
where Sys_context (' USERENV ', ' SESSIONID ') = Audsid)
where Sys_context (' USERENV ', ' SESSIONID ') = session_id;
Update User_log
Set logoff_day = Sysdate
where Sys_context (' USERENV ', ' SESSIONID ') = session_id;
Update User_log
Set elapsed_minutes = Round ((logoff_day-logon_day) * 1440)
where Sys_context (' USERENV ', ' SESSIONID ') = session_id;
End
oracle--CREATE trigger implementation to track user login information