Mega Code Archive

 
Categories / MySQL Tutorial / Procedure Function
 

Verify the input parameter

mysql> mysql> delimiter $$ mysql> mysql> CREATE FUNCTION myFunction (in_string varchar(80) )     ->  RETURNS VARCHAR(256)     ->  NO SQL     -> BEGIN     ->    DECLARE i INT DEFAULT 1;     ->       DECLARE string_len INT;     ->       DECLARE out_string VARCHAR(256) DEFAULT '';     ->     ->       SET string_len=length(in_string);     ->       WHILE (i<string_len) DO     ->          SET out_string=CONCAT(out_string,ASCII(substr(in_string,i,1)),' ');     ->          SET i=i+1;     ->       END WHILE;     ->       RETURN (out_string);     ->     -> END$$ Query OK, 0 rows affected (0.00 sec) mysql> mysql> delimiter ; mysql> mysql> select myFunction('ABCDEFGHI'); +--------------------------+ | myFunction('ABCDEFGHI')  | +--------------------------+ | 65 66 67 68 69 70 71 72  | +--------------------------+ 1 row in set (0.00 sec) mysql> mysql> drop function myFunction; Query OK, 0 rows affected (0.00 sec) mysql>