Mysql储存过程5: while
Posted FireC@t @ Perl6
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mysql储存过程5: while相关的知识,希望对你有一定的参考价值。
循环结构 while create procedure name() begin while 条件 do SQL语句 end while; end$ create procedure aa6() begin declare number int default 0; while number < 5 do select number; set number = number + 1; end while; end$
mysql> create procedure aa6()
-> begin
-> declare number int default 0;
-> while number < 5 do
-> select number;
-> set number = number + 1;
-> end while;
-> end$
Query OK, 0 rows affected (0.00 sec)
mysql> call aa6$
+--------+
| number |
+--------+
| 0 |
+--------+
1 row in set (0.00 sec)
+--------+
| number |
+--------+
| 1 |
+--------+
1 row in set (0.01 sec)
+--------+
| number |
+--------+
| 2 |
+--------+
1 row in set (0.01 sec)
+--------+
| number |
+--------+
| 3 |
+--------+
1 row in set (0.01 sec)
+--------+
| number |
+--------+
| 4 |
+--------+
1 row in set (0.02 sec)
Query OK, 0 rows affected (0.02 sec)
以上是关于Mysql储存过程5: while的主要内容,如果未能解决你的问题,请参考以下文章