本节分享一段mysql实例代码,学习mysql中repeat语句的用法。
代码如下:
mysql> DELIMITER // mysql> CREATE FUNCTION myFunction (quantity INT(10)) RETURNS INT(10) --//创建mysql函数 -> BEGIN -> -> REPEAT ---//mysql repeat语句的例子 -> SET quantity = quantity + 1; -> UNTIL quantity MOD 12 = 0 -> END REPEAT; -> -> RETURN quantity; -> -> END -> // Query OK, 0 rows affected (0.00 sec) mysql> delimiter ; mysql> select myFunction(10); //调用mysql函数 +----------------+ | myFunction(10) | +----------------+ | 12 | +----------------+ 1 row in set (0.00 sec) mysql> select myFunction(24); //调用mysql函数 +----------------+ | myFunction(24) | +----------------+ | 36 | +----------------+ 1 row in set (0.00 sec) mysql> drop function myFunction; //删除mysql函数 Query OK, 0 rows affected (0.00 sec)