MySQL Forums
Forum List  »  Stored Procedures

insert doble last records- cursor/ insert
Posted by: Luis Saavedra
Date: July 15, 2014 02:13PM

Hola a todos,

Por favor necesito ayuda con este store procedure, continuaciĆ³n detallo su funcionalidad:


1.- Leer N registros y por cada uno hace un insert en otra tabla(Insert Into temp, no me genero la tabla temporal tuve que crearlo fisicamente).

El problema es que el ultimo registro lo hace dos veces Ejemplo:
en vez de copiar


1,Peru
2,Ecuador
3,Chile

Copia
1,Peru
2,Ecuador
3,Chile
4,Chile




DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `duplicar_registros_idiomas`(in paramId int)
BEGIN
declare count int;
declare count_1 int;
declare filas INT;
declare var_nombre varchar(255);
DECLARE done INT DEFAULT FALSE;

DECLARE cur CURSOR FOR SELECT nombre FROM paises WHERE id < paramId;


#declare handle
declare continue HANDLER FOR NOT FOUND SET done = TRUE;

delete from temp;

#OPEN CURSOR
OPEN cur;
set done = false;
repeat
#iniciando el loop
FETCH cur INTO var_nombre;

if(var_nombre is null = false) then
insert into temp (nombre,idioma_id) values (var_nombre,'EN');
END IF;
until done end repeat;

close cur;

SELECT * FROM temp;

end

Options: ReplyQuote


Subject
Views
Written By
Posted
insert doble last records- cursor/ insert
3131
July 15, 2014 02:13PM


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.