Verify the input parameter : Parameters « Procedure Function « SQL / MySQL






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>
mysql>

          
    
    
  








Related examples in the same category

1.DateTime parameter
2.Check input parameter
3.Declare and use the OUT parameter
4.Save status to an OUT parameter
5.Pass status code and message out of a procedure
6.Using OUT parameter to return the status code and message from a procedure
7.Pass variable to a procedure as the OUT parameter
8.Out parameter
9.Three inout parameters
10.Syntax for Function Parameters
11.Create a procedure with out parameter
12.Syntax for Parameters of Procedures
13.Four out parameters
14.Assign value to an out parameter