教程集 www.jiaochengji.com
教程集 >  数据库  >  mysql  >  正文 mysql函数中使用repeat循环的例子

mysql函数中使用repeat循环的例子

发布时间:2015-12-30   编辑:jiaochengji.com
本文分享一个mysql中使用repeat循环的例子,供大家学习参考。

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)

您可能感兴趣的文章:
mysql函数中使用repeat循环的例子
mysql实例 repeat语句的用法
mysql循环语句的例子:Repeat until loop
mysql存储过程中的三种循环
分享:Mysql 5.0存储过程学习总结
mysql实例 循环结构中使用if语句
mysql循环结构 Repeat ... until循环中使用游标
mysql functions实例:loop循环 concat函数返回长串星号
MySQL 存储过程中使用 WHILE 循环语句的例子
mysql实例 循环语句中插入数据

[关闭]
~ ~