创建触发器时,报错“ora-04082:NEW or OLD references not allowed in table level triggers”
创建触发器tri_pt产生错误:
SQL> create or replace trigger tri_pt
2 after delete on student2
3 declare
4 v_dept_id number;
5 begin
6 v_dept_id := :old.dept_id
7 end;
8 /
Error: ora-04082: NEW or OLD references not allowed in table level triggers
【原因】
:new 和 :old 适用于行级触发器。本例中定义的触发器不是行级触发器。
【解决方法】
将触发器改为行级触发器
SQL> create or replace trigger tri_pt
2 after delete on student2
3 for each row ------------添加此行脚本
4 declare
5 v_dept_id number;
6 begin
7 v_dept_id := :old.dept_id
8 end;
9 /