An example of a LOOP: test(n) returns once again a string with n asterisks.
mysql>
mysql>
mysql> delimiter $$
mysql>
mysql> CREATE FUNCTION test (n INT) RETURNS TEXT
-> BEGIN
-> DECLARE i INT DEFAULT 0;
-> DECLARE s TEXT DEFAULT '';
-> myloop: LOOP
-> SET i = i+1;
-> SET s = CONCAT(s, "*");
-> IF i>=n THEN LEAVE myloop;
-> END IF;
-> END LOOP myloop;
-> RETURN s;
-> END$$
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> delimiter ;
mysql>
mysql>
mysql>
Related examples in the same category