26
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

1
  • 3
    You should accept the answer, because it's correct. Commented Jun 8, 2012 at 14:43

2 Answers 2

67

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 ;
Sign up to request clarification or add additional context in comments.

1 Comment

this should be marked as answer, thanks John Flatness
-4

Remove the DECLARE, you should be able to just do this:

SET @x = 0;

Also, variables need to be prefixed with the @ symbol

3 Comments

Unrelated to the question, but this really helped me.
This will create variables that are visible to the whole session, you just want to declare them as then they are visible only inside the stored procedure.
Agree with Skiwi.. this is a real bad answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.