REPEAT Statement : Repeat until « Procedure Function « SQL / MySQL






REPEAT Statement

  
mysql>
mysql>
mysql> DELIMITER //
mysql> CREATE FUNCTION myFunction (quantity INT(10)) RETURNS INT(10)
    -> BEGIN
    ->
    ->     REPEAT
    ->     SET quantity = quantity + 1;
    ->     UNTIL quantity MOD 12 = 0
    ->     END REPEAT;
    ->
    ->     RETURN quantity;
    ->
    -> END
    -> //
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> delimiter ;
mysql> select myFunction(10);
+----------------+
| myFunction(10) |
+----------------+
|             12 |
+----------------+
1 row in set (0.00 sec)

mysql>
mysql> select myFunction(24);
+----------------+
| myFunction(24) |
+----------------+
|             36 |
+----------------+
1 row in set (0.00 sec)

mysql>
mysql>
mysql> drop function myFunction;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>

          
  








Related examples in the same category

1.Repeat until loop
2.Using Repeat ... until to loop through a cursor
3.Using Repeat