trigger_nestlevel()能完成怎样的功能?
解决方案 »
- 编译release版的QMYSQL和QOCI
- oracle 日期
- 求高手、达人指点sql语句
- 求肋高手,有关分组查询的问题?
- 一个SQL的问题
- 命中率大于98%,还需要将某些基础数据表ALTER TABLE CACHE吗
- 使用cursor?还是不使用Cursor?这是一个问题。高分望高手相助
- 监听的基础问题,牛牛们救命啊~~~
- 急!请问oracle9.01触发器为什么导出又重新导入状态变为invalid?
- 联机日志损坏,怎么恢复?
- 如何在delphi程序中运行oracle的sql脚本文件?
- 请问SQL问题:如何实现类似的功能select field1 as fi,field2 as f2,f1*f2 from A;谢谢
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 行。