任何人都可以解释,为什么以下MySQL存储函数返回总是null?如果我将exchange_rate
中的SET @dollar = euro * exchange_rate;
替换为1.1013则效果很好。
DROP FUNCTION IF EXISTS euro_to_dollar;
DELIMITER $$
CREATE FUNCTION euro_to_dollar(euro double) returns double
BEGIN
DECLARE dollar double;
DECLARE exchange_rate double;
SET @exchange_rate = 1.1013;
SET @dollar = euro * exchange_rate;
RETURN @dollar;
END $$
DELIMITER ;
答案 0 :(得分:0)
你必须像这样引用@exchange_rate:
DROP FUNCTION IF EXISTS euro_to_dollar;
DELIMITER $$
CREATE FUNCTION euro_to_dollar(euro double) returns double
BEGIN
DECLARE dollar double;
DECLARE exchange_rate double;
SET @exchange_rate = 1.1013;
SET @dollar = euro * @exchange_rate;
RETURN @dollar;
END $$
DELIMITER ;