Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

syntax error for mysql declaration of variable

Tags:

CREATE PROCEDURE dorepeat(IN p1 INT) BEGIN   DECLARE x INT DEFAULT 0;   REPEAT SET x = x + 1; UNTIL x > p1 END REPEAT; END 

I get an syntax error:

#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 '' at line 3

But for me, everything seems to be correct. i really don't have any clue! can anybody help?

thanks

like image 958
moris Avatar asked Sep 13 '11 20:09

moris


People also ask

Why declare is not working in MySQL?

According to the MySQL manual, DECLARE is only allowed inside a BEGIN ... END block, and must be at the start. You're also forgetting a semicolon on the end of each line.

What is syntax error in MySQL?

The MySQL 1064 error is a syntax error. This means the reason there's a problem is because MySQL doesn't understand what you're asking it to do. However, there are many different situations that can lead to this type of miscommunication between you and your database.

How do you declare a variable syntax?

The declaration of a variable generally takes the following syntax: dataType variableName ; dataType variableName ; Where dataType is a type-specifier which is any Java data type and variableName is the unique name of a variable.


1 Answers

You need to temporarily change the delimiter so the MySQL client doesn't think you're done with your statement when it sees the semicolon on line 3:

DELIMITER //  CREATE PROCEDURE dorepeat(IN p1 INT) BEGIN   DECLARE x INT DEFAULT 0;   REPEAT SET x = x + 1; UNTIL x > p1 END REPEAT; END//  DELIMITER ; 
like image 199
John Flatness Avatar answered Sep 18 '22 13:09

John Flatness