MySQL Forums
Forum List  »  Triggers

Re: TRIGGER question
Posted by: shannon allen
Date: October 20, 2006 10:04AM

While still trying to solve this problem I've changed my approach slightly by using a stored procedure.

mysql> delimiter $
mysql> CREATE PROCEDURE find_plat
-> (plat INT, OUT found INT)
-> BEGIN
-> DECLARE count CURSOR FOR
-> SELECT PlatformId from PositionChangedTable WHERE PlatformId=plat;
-> OPEN count;
-> FETCH count INTO found;
-> close count;
-> END $

This procedure works when called from the mysql prompt.
I now try to call it from within my trigger:

mysql> delimiter $
mysql> CREATE TRIGGER t_poschanged
-> AFTER INSERT on Positiontable
-> For Each Row
-> Call find_plat(New.PlatformId,@found);
-> if (@found=0) then
-> insert into positionchangedtable values(NULL,NEW.PlatformId,NEW.Time);
-> else
-> update positionchangedtable SET Id=NULL, Time=NEW.Time;
-> end if;
-> END $

but get this errror:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if (@
found=0) then
insert into positionchangedtable values(NULL,NEW.Platfo' at line 1

Any ideas??

Options: ReplyQuote


Subject
Views
Written By
Posted
2004
October 18, 2006 02:36PM
Re: TRIGGER question
1545
October 20, 2006 10:04AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.