create or replace
trigger audit_att_eval
AFTER INSERT OR UPDATE OF evaluation ON attendance
FOR EACH ROW
DECLARE
fname VARCHAR2(22);
sname VARCHAR2(22);
ctitle VARCHAR(30);
ostartdate DATE;
oinstructor VARCHAR2(12);
BEGIN
SELECT student.first_name, student.surname, course.title, offering.start_date, offering.instructor
INTO fname, sname, ctitle, ostartdate, oinstructor
FROM student, course, offering, attendance
WHERE student.student_id = attendance.student_id
AND attendance.offering_id = offering.offering_id
AND offering.course_id = course.course_id;
IF (:NEW.evaluation = 0)
THEN
INSERT INTO eval_audit
VALUES (fname, sname, ctitle, ostartdate, oinstructor, :NEW.evaluation);
END IF;
END;
これはコンパイルされますが、既存のattendance.evaluationを更新しようとしてこれをテストすると、次のエラーが発生します:
Error report:
SQL Error: ORA-04091: table.ATTENDANCE is mutating, trigger/function may not see it
ORA-04088: error during execution of trigger 'OPS$1022005.AUDIT_ATT_EVAL'
04091. 00000 - "table %s.%s is mutating, trigger/function may not see it"
*Cause: A trigger (or a user defined plsql function that is referenced in
this statement) attempted to look at (or modify) a table that was
in the middle of being modified by the statement which fired it.
*Action: Rewrite the trigger (or function) so it does not read that table.
いつものように、私を正しい方向に導くための助けをいただければ幸いです。