BEGIN
DECLARE A FLOAT;
CASE
when `num` >1 then set A =`num`
DECLARE A FLOAT;
CASE
when `num` >1 then set A =`num`
end CASE
RETURN A;
END
就这么简单个语法,到底哪不对!
加了个case就报错 num 是input参数
解决方案:40分
注意 分号,另外,要写 no sql
mysql> delimiter $$ mysql> CREATE DEFINER=`root`@`%` FUNCTION `func`( num int) -> RETURNS int(11) -> NO SQL -> BEGIN -> declare a float; -> case when num >1 then -> set a = num; -> end case; -> RETURN a; -> end$$ Query OK, 0 rows affected (0.01 sec) mysql> delimiter ; mysql> select func(1234); +--+ | func(1234) | +--+ | 1234 | +--+ 1 row in set (0.00 sec)