How to go through a regristro of a query, and pass the values that are obtained as a parameter to another Store Procedure in Mysql?

0

I have the following Store Procedure:

        DELIMITER $$

        USE 'open_bd'$$

        DROP PROCEDURE IF EXISTS 'LlamarEjemplo'$$

        CREATE DEFINER='root'@'localhost' PROCEDURE 'LlamarLibroCompras_ListarMesPeriodo'(IN rutempresaC VARCHAR(10),IN periodoC INT, IN mesC INT)
        BEGIN
            DECLARE c_noint INT(12) ;
            DECLARE done     TINYINT DEFAULT 0; 
            DECLARE cursor_ejemplo CURSOR FOR
            SELECT noint FROM lcomp WHERE periodo=periodoC AND mes=mesC AND rutempresa=rutempresaC; 
            DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
            DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
        OPEN cursor_ejemplo;
        loop1:LOOP

               FETCH cursor_ejemplo INTO c_noint;
                   IF done THEN
                LEAVE loop1;
               END IF;
               IF done=1 THEN
              LEAVE loop1;
               ELSE 
              CALL Ejemplo_parametros(rutempresaC,periodoC, mesC,c_noint);       
               END IF; 
        END LOOP loop1;
        CLOSE cursor_ejemplo;

 END$$

 DELIMITER ;

What I want is that as I go through the row of the query declared in the cursor cursor_example, I can send the noint value of the lcomp table. What I'm trying to do, and store it in a cursor variable c_noint, and as you go through the row of the table, you will be sending the result as a parameter to Example_parameters. But it does not work for me, since it sends me only one record of the table.

I would like to know how to make such an objective, sending as a parameter the values that are going through in the record of the table.

    
asked by Danilo 21.11.2016 в 23:35
source

1 answer

-2

Hello you can send values in the select, but it would be calling a function instead of a store, already within this function called Example_parameters sent to call the store with the same parameters.

SELECT
 CASE noint
 WHEN 1 THEN 
 Ejemplo_parametros(rutempresaC,periodoC, mesC,c_noint)
 when 0 then
  '' end 
 FROM lcomp WHERE periodo=periodoC AND mes=mesC AND rutempresa=rutempresaC; 

I hope it helps you.

Greetings.

    
answered by 22.11.2016 в 04:26