Using Repeat
mysql>
mysql> delimiter $$
mysql>
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>
mysql> delimiter ;
mysql>
mysql> SELECT test(5);
+---------+
| test(5) |
+---------+
| ***** |
+---------+
1 row in set (0.00 sec)
mysql>
mysql>
mysql>
mysql> drop function test;
Query OK, 0 rows affected (0.00 sec)
mysql>
Related examples in the same category