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> 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> drop procedure myProc;
Query OK, 0 rows affected (0.00 sec)
mysql> drop function isodd;
Query OK, 0 rows affected (0.00 sec)
mysql>