Skip to content

ITERATE

DELIMITER //
CREATE PROCEDURE iterate_example()
BEGIN
SET @x = 0;
LOOP
SET @x = @x + 1;
SELECT @x;
IF @x >= 10 THEN
LEAVE LOOP;
END IF;
END LOOP;
END //
DELIMITER ;
CALL iterate_example();
1
2
3
4
5
6
7
8
9
10

This is a simple example of the ITERATE statement in MySQL. The code initializes a variable @x to 0 and creates a loop that increments @x by one and prints it out. When @x reaches 10, it exits the loop. The output displays the values of @x as they are updated, from 1 to 10.