mysq 存储过程怎么调用自定义函数

2024-11-27 12:43:45
推荐回答(1个)
回答1:

call
或,如果在select中调用,直接写func()
~~~~~~~~~~~~~~~~~~~~~~~
mysql> delimiter $$
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> CREATE PROCEDURE myProc(aNumber int) //创建mysql存储过程
-> Begin
-> IF (isodd(aNumber)) THEN
-> SELECT ' is odd';
-> ELSE
-> SELECT ' is even';
-> END IF;
-> END$$
Query OK, 0 rows affected (0.02 sec)