'MYSQL Procedure for while loop to add date

I am creating a table in mysql that needs to add incrementing date with a 3 hour interval between 2000-01-01 00:00:00 through 2020-01-01 00:00:00.

I created a table my_table with he primary key as time_key. I made this procedure to create a while loop to insert the dates into table.

mysql> CREATE PROCEDURE loop_date()
    -> BEGIN 
    -> SET @dateStart DEFAULT '2021-01-01 03:00:00';
    -> WHILE (dateStart < '2020-01-01 00:00:00') DO
    -> INSERT INTO my_table(time_key) VALUES (dateStart);
    -> set dateStart = dateStart + INTERVAL 3 HOUR;
    -> END WHILE;
    -> END;
    -> //
    -> DELIMITER;
 
    -> CALL loop_date();

I am getting an error 1054 unknown column 'dateStart' in field list



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source