gpt4 book ai didi

mysql - 存储过程返回空值

转载 作者:行者123 更新时间:2023-11-29 17:49:07 25 4
gpt4 key购买 nike

我正在制作一个存储过程,根据一个人每月的总交易量提供现金返还,但调用时它显示现金返还为空值

CREATE DEFINER=`root`@`localhost` PROCEDURE `stored_procedure_cashback`(IN a INT, IN b INT)
BEGIN
DECLARE cashback_get INT;
DECLARE total INT;
SELECT customers.`id_customers`, customers.`customers_name`, MONTH(transaction.`transaction_date`) AS month,
YEAR(transaction.`transaction_date`) AS year,
SUM((transaction_detail.`ammount`*transaction_detail.`price_per_piece`)-transaction_detail.`discount`) AS total,
cashback_get
FROM transaction_detail
INNER JOIN transaction ON transaction_detail.`id_transaction`=transaction.`id_transaction`
INNER JOIN customers ON transaction.`id_customers`=customers.`id_customers`
WHERE MONTH(transaction.`transaction_date`) = a AND YEAR(transaction.`transaction_date`) = b
GROUP BY customers.`id_customers`;

IF (total >= 20000) THEN
SET cashback_get = 2000;
ELSE
SET cashback_get = 0;
END IF;

最佳答案

您错误地将结果作为 OUT 参数。

CREATE DEFINER=`root`@`localhost` PROCEDURE. 
`stored_procedure_cashback`(IN a INT, IN b INT, OUT cashback_get INT)
BEGIN

DECLARE total INT;
SELECT Sum( etc etc) into total
From table
etc etc

IF total >= 20000 Then
SET cashback_get = 2000;
ELSE
SET cashback_get = 0;
END IF;

END;

关于mysql - 存储过程返回空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49547322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com