mysq 存储过程怎么调用自定义函数
2017-11-15
展开全部
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)
或,如果在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)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询