Repeat until loop : Repeat until « Procedure Function « MySQL Tutorial






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)








11.19.Repeat until
11.19.1.REPEAT Statement
11.19.2.Repeat until loop
11.19.3.Using Repeat ... until to loop through a cursor