简体   繁体   中英

Mysql stored Procedure syntax error 1064

I have a MySQL Stored Procedure. It is like this:

CREATE PROCEDURE dorepeat(p1 INT)
BEGIN
SET @x = 1;
REPEAT

INSERT INTO `edittables` (`USER_ID`, `REFERENCETYPE`, `COLUMNNAME`, `VERSION`, `CREATEDDATETIME`, `LASTUPDATEDDATETIME`) VALUES
  (@x ,12,'type', 0, "2014-08-12 00:00:00", "2000-08-12 00:00:00");

SET @x = @x + 1;
UNTIL @x > p1 END REPEAT;
END
//

I get this error:

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 'REPEAT

INSERT INTO `edittables` (`USER_ID`, `REFERENCETYPE`, `COLUMNNAM' at line 1

Any idea?

Try this

DELIMITER //   
CREATE PROCEDURE dorepeat(p1 INT)
BEGIN
    DECLARE x  INTEGER;
    SET x = 1;
    REPEAT
         INSERT INTO `edittables` (`USER_ID`, `REFERENCETYPE`, `COLUMNNAME`,`VERSION`, `CREATEDDATETIME`, `LASTUPDATEDDATETIME`) VALUES (X ,12,'type', 0, "2014-08-12 00:00:00", "2000-08-12 00:00:00");
         SET  x = x + 1;
    UNTIL x > p1
    END REPEAT;    
END //
DELIMITER ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM