MySQL Forums
Forum List  »  Stored Procedures

Re: procedure with if
Posted by: Ale Diaz Velasquez
Date: April 18, 2019 12:35PM

DELIMITER $$
CREATE PROCEDURE guardarConbp()
BEGIN
declare v_numcc varchar(6);
declare v_rutprov varchar(10);
declare v_serie VARCHAR(3);
declare v_fecha DATE;
declare v_monto int;
declare v_numcheq int;
declare v_nummov int;
declare v_numfact VARCHAR(9);
declare getConbp int DEFAULT 0;
declare nameColumn int = 0;
declare cursor_conbp cursor for select CONBP_NUMEROCC, CONBP_RUTPROV, CONBP_SERIE, CONBP_FECHA, CONBP_MONTO, CONBP_NUMCHEQ, CONBP_NUMMOV, CONBP_NUMFAC from tbl_conbp where `CONBP_MONTO` != 0;
declare continue handler for not found set getConbp=1;
open cursor_conbp;
getConbp : LOOP FETCH
cursor_conbp INTO v_numcc, v_rutprov, v_serie, v_fecha, v_monto, v_numcheq, v_nummov, v_numfact;
if getConbp = 1 then
if(cursor_conbp) then
INSERT INTO reg_conbp(`NEW_CONBP_NUMEROCC`, `NEW_CONBP_RUTPROV`, `NEW_CONBP_SERIE`, `NEW_CONBP_FECHA`, `NEW_CONBP_MONTO`, `NEW_CONBP_NUMCHEQ`, `NEW_CONBP_NUMMOV`, `NEW_CONBP_NUMFAC`) VALUES( v_numcc, v_rutprov, v_serie, v_fecha, v_monto, v_numcheq, v_nummov, v_numfact);
ELSE )
ALTER TABLE reg_conbp add concat_ws("",NEW_CONBP_FECHA,nameColumn) date, concat_ws("",NEW_CONBP_MONTO,nameColumn) integer;
UPDATE reg_conbp SET NEW_CONBP_FECHA = v_fecha and NEW_CONBP_MONTO = v_monto WHERE NEW_CONBP_RUTPROV = v_rutprov ;
nameColumn ++;
end if;
leave getConbp;
end if;

end loop getConbp;
close cursor_conbp;


END; $$

DELIMITER ;

Options: ReplyQuote


Subject
Views
Written By
Posted
1126
April 17, 2019 02:06PM
401
April 18, 2019 09:33AM
Re: procedure with if
382
April 18, 2019 12:35PM
382
April 18, 2019 01:52PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.