mysql循环语句的例子:Repeat until loop

发布时间:2020-05-20编辑:脚本学堂
本文介绍下,mysql中循环语句until的例子,学习下repeat until loop的具体用法,有需要的朋友可以参考下。

分享下mysql中unitl循环的用法实例,供大家参考。

代码如下:

mysql> delimiter //
mysql> create procedure test_repeat (IN in_count INT) //创建一个mysql存储过程
    -> BEGIN
    ->     declare count INT default 0;
    ->
    ->     increment: repeat
    ->         set count = count + 1;
    ->         select count;
    ->         until count > 10
    ->     end repeat increment;
    ->
    -> END
    -> //
Query OK, 0 rows affected (0.00 sec)

mysql> delimiter ;
mysql> call test_repeat(10); //调用mysql存储过程
+-------+
| count |
+-------+
|     1 |
+-------+
1 row in set (0.00 sec)

+-------+
| count |
+-------+
|     2 |
+-------+
1 row in set (0.00 sec)

+-------+
| count |
+-------+
|     3 |
+-------+
1 row in set (0.01 sec)

+-------+
| count |
+-------+
|     4 |
+-------+
1 row in set (0.01 sec)

+-------+
| count |
+-------+
|     5 |
+-------+
1 row in set (0.01 sec)

+-------+
| count |
+-------+
|     6 |
+-------+
1 row in set (0.01 sec)

+-------+
| count |
+-------+
|     7 |
+-------+
1 row in set (0.01 sec)

+-------+
| count |
+-------+
|     8 |
+-------+
1 row in set (0.01 sec)

+-------+
| count |
+-------+
|     9 |
+-------+
1 row in set (0.01 sec)

+-------+
| count |
+-------+
|    10 |
+-------+
1 row in set (0.01 sec)

+-------+
| count |
+-------+
|    11 |
+-------+
1 row in set (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

mysql>
mysql> drop procedure test_repeat; //删除mysql存储过程
Query OK, 0 rows affected (0.00 sec)