[begin_label
:] REPEATstatement_list
UNTILsearch_condition
END REPEAT [end_label
]
The statement list within a
REPEAT
statement is repeated until the
search_condition
is true. Thus, a
REPEAT
always enters the loop at least once.
statement_list
consists of one or
more statements, each terminated by a semicolon
(;
) statement delimiter.
A
REPEAT
statement can be labeled. end_label
cannot be given unless begin_label
also is present. If both are present, they must be the same.
Example:
mysql>delimiter //
mysql>CREATE PROCEDURE dorepeat(p1 INT)
->BEGIN
->SET @x = 0;
->REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;
->END
->//
Query OK, 0 rows affected (0.00 sec) mysql>CALL dorepeat(1000)//
Query OK, 0 rows affected (0.00 sec) mysql>SELECT @x//
+------+ | @x | +------+ | 1001 | +------+ 1 row in set (0.00 sec)
User Comments
Add your own comment.