MySQL Forums
Forum List  »  Triggers

problem with pre-define variable
Posted by: selaru sibath
Date: February 03, 2014 09:38AM

below code is working correctly,
-----------------------------------------
CREATE TRIGGER `tr_update_cement_table` AFTER INSERT ON `bring`
FOR EACH ROW
BEGIN

SELECT ship_id INTO @i FROM bring ORDER BY permit_id desc LIMIT 1;
SELECT bring_capacity, cement_code into @q,@id from bring WHERE ship_id=@i;
SELECT current_stoke INTO @cstk FROM cement_factory_db.cement WHERE cement_code = @id;
UPDATE cement_factory_db.cement SET current_stoke = @q+@cstk WHERE cement_code = @id;
END
-----------------------------------------------
if I add DECLARE @i int; statement as below it generate an error. I can not understand why. can anyone help me ?
-----------------------------------------------
BEGIN
DECLARE @i int;

SELECT ship_id INTO @i FROM bring ORDER BY permit_id desc LIMIT 1;
SELECT bring_capacity, cement_code into @q,@id from bring WHERE ship_id=@i;
SELECT current_stoke INTO @cstk FROM cement_factory_db.cement WHERE cement_code = @id;
UPDATE cement_factory_db.cement SET current_stoke = @q+@cstk WHERE cement_code = @id;
END
---------------------------------------------------
#1064 - 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 '@i int; SELECT ship_id INTO @i FROM bring ORDER BY permit_id desc LIMIT 1; ' at line 2

Options: ReplyQuote


Subject
Views
Written By
Posted
problem with pre-define variable
1930
February 03, 2014 09:38AM
1110
February 03, 2014 08:31PM
989
February 04, 2014 07:07AM
1065
February 04, 2014 03:30PM


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.