Hello.


It seems that you forgot to OPEN the cursor. The trigger should be

similar to this one:



CREATE TRIGGER trigger_registration_and_attendance_before_insert

BEFORE INSERT

ON registration_and_attendance

FOR EACH ROW

BEGIN

  DECLARE schedule_class_id INT;

  DECLARE schedule_class_id_cursor CURSOR FOR

    SELECT class_id

    FROM schedules

    WHERE schedules.id = new.schedule_id;

  OPEN schedule_class_id_cursor;

  FETCH schedule_class_id_cursor INTO schedule_class_id;

  SET new.class_id = schedule_class_id;

  CLOSE schedule_class_id_cursor ;

END;







Ferindo Middleton Jr wrote:

> Is it possible to SET values on fields that involve the TABLE that

> invoked the TRIGGER with SET actions.

> I have the following lines in my trigger:

> 

> delimiter //

> CREATE TRIGGER trigger_registration_and_attendance_before_insert

> BEFORE INSERT

> ON registration_and_attendance

> FOR EACH ROW

> BEGIN

>    DECLARE schedule_class_id INT;

>    DECLARE schedule_class_id_cursor CURSOR FOR SELECT class_id FROM

> schedules WHERE schedules.id =                                        

> new.schedule_id;

>    FETCH schedule_class_id_cursor INTO schedule_class_id;

>    SET new.class_id = schedule_class_id;

> END;

> 

> The server accepts this but "new.class_id" doesn't get a value when I do

> an INSERT. Why won't this work?

> 

> Ferindo

> 



-- 
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.NET http://www.ensita.net/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Gleb Paharenko
 / /|_/ / // /\ \/ /_/ / /__   [EMAIL PROTECTED]
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.NET
       <___/   www.mysql.com




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to