While loop : While « Procedure Function « MySQL Tutorial






mysql>
mysql>
mysql> delimiter //
mysql> create procedure test_while (IN in_count INT)
    -> BEGIN
    ->     declare count INT default 0;
    ->
    ->     while count < 10 do
    ->         set count = count + 1;
    ->     end while;
    ->
    ->     select count;
    -> END
    -> //
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> delimiter ;
mysql>
mysql> call test_while(10);
+-------+
| count |
+-------+
|    10 |
+-------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> drop procedure test_while;
Query OK, 0 rows affected (0.00 sec)








11.14.While
11.14.1.WHILE Statement
11.14.2.While loop
11.14.3.IF statement in a While loop