Mysql存储过程语法错误1064

时间:2014-08-13 06:19:21

标签: mysql stored-procedures

我有一个MySQL存储过程。就像这样:

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
//

我收到此错误:

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

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

试试这个

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 ;