[begin_label
:] REPEATstatement_list
UNTILsearch_condition
END REPEAT [end_label
]
The statement list within a REPEAT
statement is repeated until the search_condition
expression is true. REPEAT
语句中的语句列表将重复,直到搜索条件表达式为true
。Thus, a 因此,REPEAT
always enters the loop at least once. REPEAT
总是至少进入循环一次。statement_list
consists of one or more statements, each terminated by a semicolon (;
) statement delimiter.statement_list
由一个或多个语句组成,每个语句以分号(;
)结尾语句分隔符。
A REPEAT
statement can be labeled. REPEAT
语句可以加标签。For the rules regarding label use, see Section 13.6.2, “Statement Labels”.有关标签使用的规则,请参阅第13.6.2节,“语句标签”。
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)