为什么这个MySQL存储函数返回null?

时间:2015-05-23 15:26:25

标签: mysql sql stored-functions

任何人都可以解释,为什么以下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 ;

1 个答案:

答案 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 ;