MySQL syntax error in WHILE statement

mysql

Solution

The procedure looks ok I guess you are missing the delimiter

delimiter //
CREATE PROCEDURE dowhile()
  BEGIN
   DECLARE v1 INT DEFAULT 5;
    WHILE v1 > 0 DO
     SET v1 = v1 - 1;
   END WHILE;
 END; //
delimiter ;

Problem

I'm working through learning MySQL (v 5.6) and trying to get a simple `WHILE` loop to go through. I even just straight copy & paste from the manual (with added `SELECT v1;` statement). ``` CREATE PROCEDURE dowhile() BEGIN DECLARE v1 INT DEFAULT 5; WHILE v1 > 0 DO SELECT v1; SET v1 = v1 - 1; END WHILE; END; ``` Workbench is giving me this error: CREATE PROCEDURE dowhile() BEGIN DECLARE v1 INT DEFAULT 5 Error Code: 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 0.001 sec Any insight from more experienced MySQL programmers is very appreciated!

Original source

Related problems