Answers:
触发器on schema
(未指定架构)不会针对所有架构触发。仅当触发操作由拥有该触发器的用户运行时才会触发。
因此它们是完全不同的,并且不能互换。
这是一个设置日志表和三个create
触发器的示例:on database
,并且on schema
针对用户foo
和bar
:
Connected. -- as mat
SQL> create table mat.log (dt timestamp, who varchar(3),
2 cur varchar(10), own varchar(42), obj varchar(42));
Table created.
SQL> create or replace trigger db_trig
2 after create on database
3 begin
4 insert into mat.log values (systimestamp, 'db', user,
5 ORA_DICT_OBJ_OWNER, ORA_DICT_OBJ_NAME);
6 end;
7 /
Trigger created.
SQL> connect foo/foo
Connected.
SQL> create or replace trigger foo_trig
2 after create on schema
3 begin
4 insert into mat.log values (systimestamp, 'foo', user,
5 ORA_DICT_OBJ_OWNER, ORA_DICT_OBJ_NAME);
6 end;
7 /
Trigger created.
SQL> connect bar/bar
Connected.
SQL> create or replace trigger bar_trig
2 after create on schema
3 begin
4 insert into mat.log values (systimestamp, 'bar', user,
5 ORA_DICT_OBJ_OWNER, ORA_DICT_OBJ_NAME);
6 end;
7 /
Trigger created.
现在让我们在foo
的架构中创建一个表,如下所示foo
:
SQL> connect foo/foo
Connected.
SQL> create table foo.foo_stuff (id number);
Table created.
让我们在foo
的架构中创建一个表,如下所示bar
:
SQL> connect bar/bar
Connected.
SQL> create table foo.bar_stuff (id number);
Table created.
这是我们记录的内容:
SQL> select * from mat.log order by dt;
DT WHO CUR OWN OBJ
------------------------------ --- ---------- ---------- ---------------
25-NOV-12 07.52.03.797794 PM db FOO FOO FOO_TRIG
25-NOV-12 07.52.03.828670 PM db BAR BAR BAR_TRIG
25-NOV-12 07.52.03.865334 PM foo FOO FOO FOO_STUFF
25-NOV-12 07.52.03.865579 PM db FOO FOO FOO_STUFF
25-NOV-12 07.52.03.894672 PM bar BAR FOO BAR_STUFF
25-NOV-12 07.52.03.894911 PM db BAR FOO BAR_STUFF
6 rows selected.
所以:
create trigger
语句由“全局” after create on database
触发器记录。该触发器还记录了其他所有内容。foo
的after create on schema
记录,是由完成表的创建foo
bar
的触发器记录了bar
自己运行的表创建,即使bar
在foo
的架构中创建了表也是如此。