当我尝试执行此过程时,它显示错误。
USE `metro`;
DROP procedure IF EXISTS `transaction`;
DELIMITER $$
USE `metro`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `transaction`(
IN amount_p INT,
IN id_in INT,
IN id_out INT,
IN uidd INT
)
BEGIN
DECLARE uide INT;
DECLARE amt INT;
DECLARE NOW_AMT INT DEFAULT 0;
SELECT `amount` INTO amt FROM metro.wallet WHERE `uid`=uide;
INSERT INTO metro.transactions(`amount_deducted`,`time`,`station_id_in`,`station_id_out`,`uid`)
VALUES (amount_p,now(),id_in,id_out,uid);
SELECT uidd INTO uide;
SELECT uide;
SET NOW_AMT:=@amt+amount_p;
SELECT amt;
UPDATE metro.wallet SET `uid`=uide,`amount`=NOW_AMT;
END$$
DELIMITER ;
wallet是一个包含uid和amount列的表。
错误代码1048,SQL状态23000:列'数量'不能为空 第1行第1列
执行0秒后完成,发生1个错误。
执行:
call metro.transaction(112,1,1,1);
答案 0 :(得分:0)
或许将您的AMOUNT包装在一个case语句中,如果它是NULL,您可以返回默认值。
SELECT case when `amount` is NULL then '' else `amount` END as `amount` INTO amt FROM metro.wallet WHERE `uid`=uide;