Home » Developer & Programmer » Forms » Trigger messing up my INSERTS in forms.
Trigger messing up my INSERTS in forms. [message #149066] Tue, 29 November 2005 22:51 Go to next message
Dev|anT
Messages: 22
Registered: November 2005
Junior Member
Ok I have a trigger that stops an instructor from having more then 5 lessons scheduled on the same date. In SQL*Plus the trigger works fine but when i attempt to insert new rows into the class_schedule table it fires up the error

FRM-40508: ORACLE error:unable to INSERT record


This error will only occur when the trigger is loaded, if the trigger is dropped then it will insert fine.

Here is the trigger and the procedure.

CREATE OR REPLACE PACKAGE schedule_checker
IS
  PROCEDURE lesson_checker(fk_ins_id  IN VARCHAR2,date_of  IN VARCHAR2);
  
  PROCEDURE time_check(TIME  IN NUMBER,class_she_id_vd  IN VARCHAR2);
END;

/
 
CREATE OR REPLACE PACKAGE BODY schedule_checker
IS
  PROCEDURE lesson_checker
       (fk_ins_id  IN VARCHAR2,
        date_of    IN VARCHAR2)
  IS
    total      NUMBER;
    ins_id_t   instructor.ins_id%TYPE;
    date_of_t  class_schedule.date_of%TYPE;
    CURSOR ins_count IS 
      SELECT   fk_ins_id,
               date_of,
               Count(*)
      FROM     class_schedule
      GROUP BY fk_ins_id,
               date_of;
  BEGIN
    OPEN ins_count;
    
    LOOP
      FETCH ins_count INTO ins_id_t,
      date_of_t,
      total;
      
      EXIT WHEN ins_count%NOTFOUND;
      
      IF (total >= 5) THEN
        Raise_application_error( - 20801,
                                'Instructor: ' || fk_ins_id || ' can not be assigned to more than 5 lessons on: ' || date_of_t);
      END IF;
    END LOOP;
    
    CLOSE ins_count;
  END lesson_checker;
  
  PROCEDURE time_check
       (TIME             IN NUMBER,
        class_she_id_vd  IN VARCHAR2)
  IS
  BEGIN
    IF (TIME NOT BETWEEN 09.00
                         AND 22.00) THEN
      Raise_application_error( - 20801,
                              ' Lesson can not be scheduled outside of Gym hours! ');
    END IF;
  END time_check;
END;

/

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);

END IF;

IF INSERTING THEN
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);

END IF;

IF UPDATING THEN
schedule_checker.lesson_checker(:new.fk_ins_id, :new.date_of);
END IF;

END;
/




Thanks in advance!
Re: Trigger messing up my INSERTS in forms. [message #149129 is a reply to message #149066] Wed, 30 November 2005 04:07 Go to previous messageGo to next message
NasirPanwar
Messages: 8
Registered: August 2005
Location: Faisalabad
Junior Member
I think it is mutating table error. The cause is that you can not select records in db trigger from the table having that db trigger. Press {Shift+F1} when the error occurs. Call your procedure at form level in Post Insert and Pre Update triggers.
Re: Trigger messing up my INSERTS in forms. [message #150048 is a reply to message #149066] Tue, 06 December 2005 01:43 Go to previous message
djmartin
Messages: 10181
Registered: March 2005
Location: Surges Bay TAS Australia
Senior Member
Account Moderator
Have you solved your problem?

David
Previous Topic: Calculation for a balance(non database item)
Next Topic: need a short-cut
Goto Forum:
  


Current Time: Fri Sep 20 03:43:11 CDT 2024