How a CURSOR is run on MySql, that is, having the following code:
DECLARE lc_prod CURSOR FOR
SELECT pedi_prod_clave, prod_descripcion, SUM(vaca_toneladas) vaca_toneladas
FROM scc_vales_carga, scc_pedidos, scc_productos
WHERE vaca_tavi_numero = pw_tavi_numero
AND vaca_eqpr_fecha = lw_eqpr_fecha
AND vaca_status != 'X'
AND pedi_serie = vaca_pedi_serie
AND pedi_numero = vaca_pedi_numero
AND prod_clave = pedi_prod_clave
GROUP BY pedi_prod_clave, prod_descripcion;
I know that this query can return me more than one record, I also know that the tour can be done in the following way:
OPEN lc_prod;
get_lc_prod: LOOP
FETCH lc_prod INTO lr_prod_pedi_prod_clave, lr_prod_prod_descripcion, lr_prod_vaca_toneladas;
IF not_found = 1 THEN
LEAVE get_lc_prod;
END IF;
INSERT INTO scc_t_auxiliar_prod_basc (aupb_prod_clave, aupb_prod_desc, aupb_toneladas)
VALUES (lr_prod_pedi_prod_clave, lr_prod_prod_descripcion, lr_prod_vaca_toneladas);
END LOOP;
CLOSE lc_prod;
The question is can it be done in any other way besides using FETCH ?, this doubt arises because what happens when in the SELECT of the CURSOR go more than 10-15 fields? In this case in the FECTH ... INTO would declare the 10-15 fields, besides that if I am not mistaken the fields defined in the SELECT to be consulted are the same that can be put in the INTO no?