Mega Code Archive

 
Categories / MySQL / Procedure Function
 

An example of a LOOP

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>