KingSunSha(弱水三千) 请看我的实验可以证明行级触发器是能嵌套触发的: 首先 建立 table_A、table_B、table_C 建立 table_A_insert、table_B_insert create table table_A ( id number(10,0) not null, name char(64) not null, log_time date not null ) ; / create table table_B ( id number(10,0) not null, name char(64) not null, log_time date not null ) ; / create table table_C ( id number(10,0) not null, name char(64) not null, log_time date not null ) ;
create or replace trigger table_A_insert after insert on table_A for each row begin insert into table_B values(:new.id, :new.name, sysdate); end ; / create or replace trigger table_B_insert after insert on table_B for each row begin insert into table_C values(:new.id, :new.name, sysdate); end ;然后: insert into table_A values(1,'asd',sysdate); select * from table_C; 结果:已创建 1 行。 ID NAME LOG_TIME ---------- --------------- ---------- 1 asd 06-10月-02已选择 1 行。
trigger_nestlevel() 能返回级联触发的层次。例如:
有表 table_A 和 table_B。另有触发器 table_A_insert、table_B_insert。
table_A_insert 的示意
begin
insert into table_B values(......);
end;table_B_insert 的示意
begin
--TODO ......
--我想知道当前活动是由 table_A_insert 中的代码引发的还是
直接执行命令 insert into table_B values(......) 引发的。
end;
如果你需要记录是由什么语句插入记录的,恐怕只能在表中添加一个字段来记录。或者你只需要在程序执行时判断,那恐怕只能用存储过程来处理,因为只有触发器中是无法传递参数的。
首先
建立 table_A、table_B、table_C
建立 table_A_insert、table_B_insert
create table table_A
(
id number(10,0) not null,
name char(64) not null,
log_time date not null
)
;
/
create table table_B
(
id number(10,0) not null,
name char(64) not null,
log_time date not null
)
;
/
create table table_C
(
id number(10,0) not null,
name char(64) not null,
log_time date not null
)
;
create or replace trigger table_A_insert
after insert on table_A
for each row
begin
insert into table_B values(:new.id, :new.name, sysdate);
end
;
/
create or replace trigger table_B_insert
after insert on table_B
for each row
begin
insert into table_C values(:new.id, :new.name, sysdate);
end
;然后:
insert into table_A values(1,'asd',sysdate);
select * from table_C;
结果:已创建 1 行。 ID NAME LOG_TIME
---------- --------------- ----------
1 asd 06-10月-02已选择 1 行。