MySQL 流程控制repeat语句
• repeat语句是存储过程或函数中表达循环执行的一种方式
delimiter // CREATE PROCEDURE dorepeat(p1 INT) BEGIN SET @x = 0; REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT; END // delimiter ;
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.11 sec) mysql> delimiter ; mysql> call dorepeat(10); Query OK, 0 rows affected (0.00 sec) mysql> select @x; +------+ | @x | +------+ | 11 | +------+ 1 row in set (0.00 sec) mysql> call dorepeat(100); Query OK, 0 rows affected (0.00 sec) mysql> select @x; +------+ | @x | +------+ | 101 | +------+ 1 row in set (0.00 sec)

浙公网安备 33010602011771号