我创建了一个系统触发器,记录用户登录时的信息,代码如下:
create or replace trigger tr_LogOn_all
after logon on database
begin
insert into t_logon
values('1', user, systimestamp,'tr_LogOn_all');
end; 现在的问题是:为什么登录一次,会触发两次这个触发器,在表中会写入两条记录?
请大家帮帮忙,第一次接触系统触发器,完全摸不着头脑,谢谢大家!
create or replace trigger tr_LogOn_all
after logon on database
begin
insert into t_logon
values('1', user, systimestamp,'tr_LogOn_all');
end; 现在的问题是:为什么登录一次,会触发两次这个触发器,在表中会写入两条记录?
请大家帮帮忙,第一次接触系统触发器,完全摸不着头脑,谢谢大家!
USER 为 "SYS"
SQL> create table t_logon (seq varchar2(8),username varchar2(8),logontime date,m
emo varchar2(32));表已创建。SQL> create or replace trigger tr_LogOn_all
2 after logon on database
3 begin
4 insert into t_logon
5 values('1', user, systimestamp,'tr_LogOn_all');
6 end;
7 /触发器已创建SQL> show error
没有错误。
SQL> select * from t_logon;未选定行SQL> conn sys/top10@test as sysdba
已连接。
SQL> select * from t_logon;SEQ USERNAME LOGONTIME MEMO
-------- -------- -------------- --------------------------------
1 SYSMAN 09-2月 -10 tr_LogOn_all
1 SYS 09-2月 -10 tr_LogOn_allSQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';会话已更改。SQL> select * from t_logon;SEQ USERNAME LOGONTIME MEMO
-------- -------- ------------------- --------------------------------
1 SYSMAN 2010-02-09 12:07:58 tr_LogOn_all
1 SYS 2010-02-09 12:08:04 tr_LogOn_allSQL> conn scott/scott@test
已连接。
SQL> select * from sys.t_logon;
select * from sys.t_logon
*
第 1 行出现错误:
ORA-00942: 表或视图不存在
SQL> conn sys/top10@test as sysdba
已连接。
SQL> select * from t_logon;SEQ USERNAME LOGONTIME MEMO
-------- -------- -------------- --------------------------------
1 SYSMAN 09-2月 -10 tr_LogOn_all
1 SYS 09-2月 -10 tr_LogOn_all
1 SYSMAN 09-2月 -10 tr_LogOn_all
1 SCOTT 09-2月 -10 tr_LogOn_all
1 SYS 09-2月 -10 tr_LogOn_allSQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';会话已更改。SQL> select * from t_logon;SEQ USERNAME LOGONTIME MEMO
-------- -------- ------------------- --------------------------------
1 SYSMAN 2010-02-09 12:07:58 tr_LogOn_all
1 SYS 2010-02-09 12:08:04 tr_LogOn_all
1 SYSMAN 2010-02-09 12:09:03 tr_LogOn_all
1 SCOTT 2010-02-09 12:09:06 tr_LogOn_all
1 SYS 2010-02-09 12:09:26 tr_LogOn_allSQL>
测试了下,SYS登录时同时以SYSMAN登录,不知是否SYSDBA登录是否都是这样。学习了。
触发器没问题。
LOG_ID USER_NAME LOGON_TIME LOGON_MSG
------ ---------- --------------------------------- ---------------------------------
1 SCOTT 09-2月 -10 11.54.50.468000 上午 tr_LogOn_all
1 SCOTT 09-2月 -10 11.54.50.562000 上午 tr_LogOn_all
connect scott/oracle
原因找到了,可是这是为什么呢?