1
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.

1
  • 1
    Is there any reason you want 100 identical rows? Sounds like an xy problem Commented Jun 4, 2022 at 11:08

1 Answer 1

2
  1. 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.

  2. Use $$ delimiter to properly mark the end of CREATE 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 ;
Sign up to request clarification or add additional context in comments.

7 Comments

How to call repeat?
@luq891 You can use repeat1, my_repeat or whatever you want. :-)
Still not insert the rows inside the table
@luq891 Try to specify columns in INSERT statement: INSERT INTO visits (column1, column2) VALUES (value1, value2). You should also call the procedure with CALL my_repeat().
@luq891 I needed to use different fiddle, because dbfiddle.uk didn't support changing delimiter. db-fiddle.com/f/hfaqSdLPGNKyhZtMYuWdzM/0
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.