MySQL Forums
Forum List  »  Triggers

Syntax error when using "IF" statement
Posted by: Ramon Oliveira
Date: April 21, 2012 09:30AM

I'm trying to create a trigger that needs to make a verification.

I've tried the syntax from the manual:

CREATE TRIGGER upd_check BEFORE UPDATE ON account
FOR EACH ROW
BEGIN
IF NEW.amount < 0 THEN
SET NEW.amount = 0;
ELSEIF NEW.amount > 100 THEN
SET NEW.amount = 100;
END IF;
END


Of course, I changed the values in order to fit my needs. But I always get a syntax error message. I'm using the 5.5 version, whats wrong with the sintax?

I also tried a simpler version, which isn't working too:

CREATE TRIGGER upd_check BEFORE UPDATE ON teste2
FOR EACH ROW
BEGIN
IF NEW.a < 0 THEN

SET NEW.a = 0;

END IF;
END

Options: ReplyQuote


Subject
Views
Written By
Posted
Syntax error when using "IF" statement
1300
April 21, 2012 09:30AM


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.