I am familiar with the mutation error but I dont seem to be able to work this one out, if anyone could give me a hand that would be great! Thanks.
SQL> CREATE OR REPLACE PACKAGE schedule_checker IS
2
3 PROCEDURE lesson_checker
4 (fk_ins_id IN VARCHAR2,
5 date_of IN VARCHAR2);
6
7 PROCEDURE time_check
8 (time IN NUMBER,
9 class_she_id_vd IN VARCHAR2);
10 END;
11 /
Package created.
SQL>
SQL> CREATE OR REPLACE PACKAGE BODY schedule_checker IS
2 PROCEDURE lesson_checker
3 (fk_ins_id IN VARCHAR2,
4 date_of IN VARCHAR2)
5 IS
6 total number;
7 ins_id_t instructor.ins_id%type;
8 date_of_t class_schedule.date_of%type;
9
10 cursor ins_count is
11 select fk_ins_id, date_of, count(*)
12 from class_schedule
13 GROUP BY fk_ins_id, date_of;
14
15 BEGIN
16
17
18 open ins_count;
19
20 loop
21 fetch ins_count into ins_id_t, date_of_t, total;
22 exit when ins_count%NOTFOUND;
23
24 if (total > 5) then
25 raise_application_error(-20801,
26 'Instructor: ' || fk_ins_id ||
27 ' can not be assigned to more than 5 lessons on: ' || date_of_t);
28 end if;
29 end loop;
30 close ins_count;
31 end lesson_checker;
32
33 PROCEDURE time_check
34 (time IN NUMBER,
35 class_she_id_vd IN VARCHAR2)
36 IS
37 Begin
38
39 IF (time NOT BETWEEN 09.00 AND 22.00) THEN
40 raise_application_error(-20801,
41 ' Lesson can not be scheduled outside of Gym hours! ');
42
43 END IF;
44 END time_check;
45 END;
46
47 /
Package body created.
Thats my package containing 2 procedures with constraints on the class_schedule table.
Here is my trigger to fire them,
CREATE OR REPLACE TRIGGER class_schedule_trig
BEFORE INSERT OR UPDATE ON class_schedule
FOR EACH ROW
BEGIN
IF INSERTING THEN
schedule_checker.time_check(:new.time, :new.class_she_id);
schedule_checker.lesson_checker(:new.fk_ins_id, :new.date_of);
END IF;
IF UPDATING THEN
schedule_checker.time_check(:new.time, :new.class_she_id);
schedule_checker.lesson_checker(:new.fk_ins_id, :new.date_of);
END IF;
END;
/
And here is my output when i attempt to update a table!! All inserts work fine and all triggers seem to fire correctly. I jsut get mutation problems on the updates.
SQL> UPDATE class_schedule SET time = '19.00' where class_she_id = '1';
UPDATE class_schedule SET time = '19.00' where class_she_id = '1'
*
ERROR at line 1:
ORA-04091: table C3028390.CLASS_SCHEDULE is mutating, trigger/function may not see it
ORA-06512: at "C3028390.SCHEDULE_CHECKER", line 11
ORA-06512: at "C3028390.SCHEDULE_CHECKER", line 18
ORA-06512: at "C3028390.CLASS_SCHEDULE_TRIG", line 12
ORA-04088: error during execution of trigger 'C3028390.CLASS_SCHEDULE_TRIG'
Would i be able to solve this with a persistant package variable?
Any help is appriciated. Thanks