I'm getting a strange error while trying to use a MySQL trigger. I'm using XAMPP and creating the trigger using PhpMyAdmin.
The trigger's code is:
BEGIN
DECLARE stud INT(11) DEFAULT 0;
DECLARE sw CURSOR FOR
(SELECT a FROM table1 WHERE b = NEW.b);
OPEN sw;
get_loop: LOOP
FETCH sw INTO stud;
INSERT INTO inbox(a, b, c, d, e) VALUES (NEW.a, stud, "Example", NEW.a, NEW.b);
END LOOP get_loop;
END
And is called BEFORE INSERT into the table 'table2'.
What happens is that the syntax is correct, but when I try to run it triggering the event it says "#1329 - No data - zero rows fetched, selected, or processed".
I tried to find out what the real problem is, and it seems to be the line "FETCH sw INTO stud"; I tried many times and the SELECT statement DOES return the correct values, so 'sw' can't be empty... I'm stuck at this point.
There are 3 tables interested by this trigger. 'table2' is the one that triggers the event; it has some columns that are called using the keyword "NEW". The second one is table3; it is the table in which I'll insert some values after the trigger has performed its actions. Finally, there's "table1".
You have no continue handler for the cursor, as I see it. It would allow that cursor to actually do something.
From the mysql Cursor
manual page, see this.
Here too is a link to a stored proc I wrote showing a continue handler with a flag specifying done for the loop.