Call another function : Call « Procedure Function « MySQL Tutorial






mysql>
mysql> delimiter $$
mysql>
mysql> CREATE FUNCTION isodd(input_number int)
    ->        RETURNS int
    -> BEGIN
    ->         DECLARE v_isodd INT;
    ->
    ->         IF MOD(input_number,2)=0 THEN
    ->                 SET v_isodd=FALSE;
    ->         ELSE
    ->                 SET v_isodd=TRUE;
    ->         END IF;
    ->
    ->         RETURN(v_isodd);
    ->
    -> END$$
Query OK, 0 rows affected (0.01 sec)

mysql>
mysql> CREATE PROCEDURE myProc(aNumber int)
    -> Begin
    ->      IF (isodd(aNumber)) THEN
    ->           SELECT ' is odd';
    ->      ELSE
    ->           SELECT ' is even';
    ->      END IF;
    -> END$$
Query OK, 0 rows affected (0.02 sec)

mysql>
mysql> delimiter ;
mysql>
mysql>
mysql> call myProc(2);
+----------+
| is even  |
+----------+
|  is even |
+----------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

mysql>
mysql> call myProc(1);
+---------+
| is odd  |
+---------+
|  is odd |
+---------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> call myProc(4);
+----------+
| is even  |
+----------+
|  is even |
+----------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql> drop procedure myProc;
Query OK, 0 rows affected (0.00 sec)

mysql> drop function isodd;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>








11.6.Call
11.6.1.CALL Statement Syntax
11.6.2.Call another procedure
11.6.3.Call another procedure with parameter
11.6.4.Call another procedure to pass the error code
11.6.5.Call another function
11.6.6.Nested function call