所以我写了这个小的存储函数,它应该会给我带来一个juiceorder的成本。但是,我在弄清楚为什么特别是它不起作用时遇到了一些麻烦。任何帮助将不胜感激
DELIMITER $$
CREATE DEFINER=`root`@`localhost` FUNCTION `juiceOrderCost`(p_id INT) RETURNS double
BEGIN
DECLARE cost DOUBLE;
DECLARE i INT DEFAULT 0;
DECLARE numRows INT;
DECLARE numDone INT DEFAULT 1;
DECLARE cup_id INT DEFAULT 0;
DECLARE myCursor CURSOR for
SELECT cupId FROM hasJuice WHERE orderID = p_id;
OPEN myCursor;
SELECT FOUND_ROWS() INTO numRows;
FETCH myCursor INTO cup_id;
WHILE numDone <= numRows DO
SET cost = cost + juiceCupCost(cup_id);
FETCH myCursor INTO cup_id;
SET numDone = numDone + 1;
END WHILE;
CLOSE myCursor;
返回成本; END
答案 0 :(得分:1)
使用DECLARE CONTINUE HANDLER FOR NOT FOUND
访问https://dev.mysql.com/doc/refman/5.5/en/condition-handling.html