我的问题是这段代码。
DELIMITER $$
DROP PROCEDURE IF EXISTS agregar_abono$$
CREATE PROCEDURE agregar_abono(IN pid_cliente BIGINT, IN pfecha_abono DATE, IN pmonto_abono FLOAT)
BEGIN
DECLARE @idabono BIGINT;
-- OTHER CODE ...
SELECT id_abono AS idabono FROM abono WHERE fk_cliente = pid_cliente ORDER BY id_abono DESC LIMIT 1;
SELECT CONCAT('>', idabono);
CALL cobrar_abono(pid_cliente, vid_abono);
END $$
两个SELECT返回的过程:
idabono = 52 --> good! (in the first select)
CONCAT('>', idabono) = null ---> what??
我不知道因为没有将结果存储在此变量中以便在存储过程中使用。我使用AS
来存储变量。
要调用的存储过程的标题是:
CREATE PROCEDURE cobrar_abono(IN pid_cliente BIGINT, IN pid_abono BIGINT)
答案 0 :(得分:0)
你在找这个吗?
...
DECLARE idabono BIGINT;
-- OTHER CODE ...
SET idabono = (SELECT id_abono
FROM abono
WHERE fk_cliente = pid_cliente
ORDER BY id_abono DESC
LIMIT 1);
SELECT
语句本身可能会替换为
SET idabono = (SELECT MAX(id_abono)
FROM abono
WHERE fk_cliente = pid_cliente);