CREATE OR REPLACE TRIGGER scott.emp_trig_idu BEFORE
UPDATE OR INSERT OR DELETE ON scott.emp_trig
FOR EACH ROW
BEGIN
INSERT INTO scott.emp_audit (
empno,
old_sal,
new_sal,
user_name,
change_date
) VALUES (
coalesce(:old.empno, :new.empno),
:old.sal,
:new.sal,
user,
sysdate
);
END;
/ Test-Befehle:
UPDATE scott.emp_trig
SET
sal = 4999
WHERE
empno = 7934;
DELETE FROM scott.emp_trig
WHERE
empno = 7839;
INSERT INTO scott.emp_trig (
empno,
ename,
deptno,
sal
) VALUES (
817,
'Marco',
20,
5000
);
SELECT
event,
empno,
old_sal,
new_sal,
change_date,
user_name
FROM
scott.emp_audit;