Repeat until loop : Repeat until « Procedure Function « SQL / MySQL
Repeat until loop |
|
mysql>
mysql> delimiter //
mysql> create procedure test_repeat (IN in_count INT)
-> 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>
mysql> delimiter ;
mysql>
mysql> call test_repeat(10);
+-------+
| 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;
Query OK, 0 rows affected (0.00 sec)
|
|
More than 3 requests, I'll translate this to Chinese.
超过3个请求,我就会把这篇文章翻译成中文。
No comments:
Post a Comment