我如何使用select中的变量来调用存储过程?

时间:2021-04-27 19:13:25

My problem it's this code.

我的问题是这个代码。

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 $$

The procedure of the two SELECT return:

两个SELECT返回的过程:

idabono = 52                  --> good! (in the first select)
CONCAT('>', idabono) = null   ---> what?? 

I don't know because don't stored the result in this variable to use in a stored procedure. I use a AS to store the variable.

我不知道是因为没有将结果存储在此变量中以在存储过程中使用。我使用AS来存储变量。

The header of stored procedure to call is :

要调用的存储过程的标头是:

CREATE PROCEDURE cobrar_abono(IN pid_cliente BIGINT, IN pid_abono BIGINT)

1 个解决方案

#1


0  

Are you looking for this?

你在找这个吗?

...
DECLARE idabono BIGINT;
-- OTHER CODE ...
SET idabono = (SELECT id_abono
                 FROM abono 
                WHERE fk_cliente = pid_cliente 
                ORDER BY id_abono DESC 
                LIMIT 1);

The SELECT statement itself probably can be replaced with

SELECT语句本身可能会替换为

SET idabono = (SELECT MAX(id_abono)
                 FROM abono 
                WHERE fk_cliente = pid_cliente);

#1


0  

Are you looking for this?

你在找这个吗?

...
DECLARE idabono BIGINT;
-- OTHER CODE ...
SET idabono = (SELECT id_abono
                 FROM abono 
                WHERE fk_cliente = pid_cliente 
                ORDER BY id_abono DESC 
                LIMIT 1);

The SELECT statement itself probably can be replaced with

SELECT语句本身可能会替换为

SET idabono = (SELECT MAX(id_abono)
                 FROM abono 
                WHERE fk_cliente = pid_cliente);