---创建日志表记录用户登录信息
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 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 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;
原文:http://www.cnblogs.com/guipeng/p/6508777.html