DELIMITER $$
CREATE PROCEDURE repeat()
BEGIN
DECLARE i INT DEFAULT 1;
WHILE (i <= 100) DO
INSERT INTO VISITS VALUES ("C9YAoq", "2022-05-03 00:00:00");
SET i=i 1;
END WHILE;
END;
DELIMITER ;
The 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 'DELIMITER $$
CREATE PROCEDURE repeat()
BEGIN
DECLARE i INT DEFAULT 1;
' at line 1
I'm trying to insert 100 rows inside the table using the loop but that does not work.
CodePudding user response:
REPEAT
is a reserved word in MySQL. If you want to use it for userland names, you should quote it or rather use another name.Use
$$
delimiter to properly mark the end ofCREATE PROCEDURE
statement.
The result:
DELIMITER $$
CREATE PROCEDURE `repeat`()
BEGIN
DECLARE i INT DEFAULT 1;
WHILE (i <= 100) DO
INSERT INTO VISITS VALUES ("C9YAoq", "2022-05-03 00:00:00");
SET i=i 1;
END WHILE;
END$$
DELIMITER ;