当我尝试选择它时,我的存储过程总是返回一个空值。我做了一些研究,我必须指定某处OUTPUT。不知道在哪里或如何做到这一点。
delimiter $$
Create Procedure ClientPurchases (IN idClient INT, outClientAvgPurchases DECIMAL (4,2))
BEGIN
DECLARE PurchasesAvg DECIMAL(4,2) ;
set PurchasesAvg=
(SELECT AVG(PurchaseAmount)
FROM Purchase
inner join Client on idClient=Client_idClient);
SET outClientAvgPurchases= PurchasesAvg;
END$$
CALL ClientPurchase(3, @purchase );
SELECT @purchase as 'Purchase Total';
答案 0 :(得分:2)
您可以将过程参数声明为IN
,OUT
或INOUT
。
Create Procedure ClientPurchases (
IN idClient INT,
OUT outClientAvgPurchases DECIMAL (4,2))
. . .
在http://dev.mysql.com/doc/refman/5.7/en/create-procedure.html
了解详情答案 1 :(得分:2)
OUT
是一个应位于参数名称前面的关键字:
Create Procedure ClientPurchases (IN idClient INT, OUT ClientAvgPurchases DECIMAL (4,2))
...
SET ClientAvgPurchases= PurchasesAvg;