为什么这个 MySQL 存储函数 return 为空?

Why does this MySQL stored function return null?

谁能解释一下,为什么下面的 MySQL 存储函数 returns 总是空的?如果我将 SET @dollar = euro * exchange_rate; 中的 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 ;

您必须像这样引用@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 ;