别忘了分号(
;
)在中
RETURN
声明:
...
-- return @days
return @days;
...
更新
我无法重现问题:
mysql> DROP FUNCTION IF EXISTS `dayssincelastmo`;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> DELIMITER //
mysql> create function dayssincelastmo(
-> sedol varchar(255),
-> currDate datetime,
-> z_score double,
-> groupnum int
-> )
-> returns int
-> deterministic
-> begin
-> if zscore<0 then
-> select datediff(p.`Period (Formatted)`, currDate) into @days
-> from
-> price as p
-> where
-> p.G_SEDOL = sedol
-> and p.`Period (Formatted)`<=currDate
-> and p.zscore<=z_score
-> and p.`GRP MODEL NUM` = groupnum
-> order by p.`Period (Formatted)`
-> limit 1;
-> end if;
-> if zscore>=0 then
-> select datediff(p.`Period (Formatted)`, currDate) into @days
-> from
-> price as p
-> where
-> p.G_SEDOL = sedol
-> and p.`Period (Formatted)`<=currDate
-> and p.zscore>=z_score
-> and p.`GRP MODEL NUM` = groupnum
-> order by p.`Period (Formatted)`
-> limit 1;
-> end if;
-> return @days;
-> end//
Query OK, 0 rows affected (0.01 sec)
mysql> DELIMITER ;