MySQL WHILE Loop Pause with SLEEP
By using the SLEEP() function in MySQL, you can pause execution for a period of time within a while loop. The function takes a parameter indicating the number of seconds to pause. For example, to pause for 5 seconds in a while loop, you can use the following statement:
SET @i = 0;
WHILE @i < 10 DO
SELECT @i;
SET @i = @i + 1;
SLEEP(5); -- 暂停5秒
END WHILE;
In the above example, the loop will pause for 5 seconds in each iteration. You can adjust the parameter of the SLEEP() function based on your needs to control the duration of the pause.