? 触发器是存储的程序,在发生某些事件时会自动执行或触发。 一般情况发生下面列表的情况而执行
CREATE [OR REPLACE ] TRIGGER trigger_name
{BEFORE | AFTER | INSTEAD OF }
{INSERT [OR] | UPDATE [OR] | DELETE}
[OF col_name]
ON table_name
[REFERENCING OLD AS o NEW AS n]
[FOR EACH ROW]
WHEN (condition)
DECLARE
Declaration-statements
BEGIN
Executable-statements
EXCEPTION
Exception-handling-statements
END;
eg
create or replace trigger show_changes
before delete or insert or update on emps
for each row
when(NEW.empno > 0)
declare
sal_diff number;
begin
sal_diff := :NEW.sal - :OLD.sal;
dbms_output.put_line('old sal:' || :OLD.sal);
dbms_output.put_line('new sal:' || :NEW.sal);
dbms_output.put_line('diff sal:' || sal_diff);
end;
效果如下:
原文:https://www.cnblogs.com/qiudaozhang/p/9510559.html