mysql中repeat循环的例子,代码如下:
mysql> delimiter $$ mysql> CREATE FUNCTION test(n INT) RETURNS TEXT //创建带返回值的函数 -> BEGIN -> DECLARE i INT DEFAULT 0; -> DECLARE s TEXT DEFAULT ''; -> myloop: REPEAT -> SET i = i+1; -> SET s = CONCAT(s, "*"); -> UNTIL i>=n END REPEAT; -> RETURN s; -> END$$ Query OK, 0 rows affected (0.00 sec) mysql> delimiter ; mysql> SELECT test(5); +---------+ | test(5) | +---------+ | ***** | +---------+ 1 row in set (0.00 sec) mysql> drop function test; //删除mysql自定义函数 Query OK, 0 rows affected (0.00 sec)