An example of a LOOP: test(n) returns once again a string with n asterisks. : Buildin Functions « Procedure Function « SQL / MySQL






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

1.Check MySQL version
2.Call buildin math function in your procedure
3.Use Build-in SUM function in a procedure
4.Using String functions in a user-defined function
5.Return the file size by using the LOAD_FILE function