以下触发器已正确创建,并在UPDATE和INSERT语句之前触发。但是,在发出DELETE stmt时,它不显示任何内容。请帮助我在这里找到问题。
create or replace trigger tr_emp_saldiff
BEFORE INSERT OR UPDATE OR DELETE
ON emp
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
WHEN (new.emp_no > 0)
declare
sal_diff number;
begin
sal_diff := :new.salary - :old.salary;
dbms_output.put(' Old salary: ' || :old.salary);
dbms_output.put(' New salary: ' || :new.salary);
dbms_output.put_line(' Difference ' || sal_diff);
END;
/
UPDATE emp set salary = salary + 500 where dept_no = 10;
Output :
1 row(s) updated.
Old salary: 20500 New salary: 21000 Difference 500
INSERT INTO EMP VALUES(1000,'Alice',15000,'Fiona',30);
Output :
1 row(s) inserted.
Old salary: New salary: 20000 Difference
DELETE FROM emp where emp_name='Jane';
Output :
1 row(s) deleted.
在删除语句之后没有显示任何值。
答案 0 :(得分:1)
WHEN (new.emp_no > 0)
对于DELETE
不能成立,new.emp_no
为null。
删除该条件或在DELETE
上使用单独的触发器。 (根据给出的信息,无论如何,UPDATE
才有意义。INSERT
或DELETE
的薪水没有变化。)