这个查询`
delimiter $$
CREATE DEFINER=`root`@`localhost` FUNCTION `calculatePrice`(cheese VARCHAR(50), meat VARCHAR(50), veg VARCHAR(50)) RETURNS decimal(10,0)
DETERMINISTIC
BEGIN
DECLARE price DECIMAL;
SET price = (SELECT SUM(x.Price)
FROM
(
SELECT `priceFactor` AS Price FROM `tblCheese` WHERE `cheeseName` = cheese
UNION ALL
SELECT `priceFactor` AS Price FROM `tblMeat` WHERE `meatName` = meat
UNION ALL
SELECT `priceFactor` AS Price FROM `tblVeggie` WHERE `veggieName` = veg
) x );
RETURN price;
END$$
`
从 MySQL 命令行客户端调用时返回数学上正确的答案,但对于任何其他程序或从 PHP 调用时不正确(无论传递什么参数,它都返回 3。)见下文:
调用语句,如果它是模糊的,是 SELECT calculatePrice('colby', 'sausage', 'black beans');
我以前从未见过这种奇怪的东西。这一切都来自 MySQL 的同一个副本,等等。
编辑添加: phpMyAdmin 也产生查询的正确答案。