0

我的问题是这段代码。

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)
4

1 回答 1

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);
于 2013-06-02T04:56:48.433 回答