I have the following store procedure
CREATE PROCEDURE `update_ordenes`()
BEGIN
DECLARE record CURSOR FOR
SELECT ordenes.idorden, ordenes.idafiliado
FROM ordenes, afiliados
WHERE afiliados.idafiliado = ordenes.idafiliado;
OPEN record;
REPEAT
FETCH record INTO @id_orden, @id_afil_viejo;
INSERT INTO afil2(nombre, apellido, documento)
(SELECT nombre, apellido, documento
FROM afiliados
WHERE idafiliado = @id_afil_viejo);
SET @last_id = (SELECT id FROM afil2 ORDER BY id DESC LIMIT 1);
UPDATE ordenes
SET afil2 = @last_id,
ordenes.idafiliado = NULL
WHERE ordenes.idafiliado = @id_afil_viejo
AND ordenes.idorden = @orden_id;
UNTIL done END REPEAT;
END
for some reason, I get an syntax error at line FETCH record INTO @id_orden, @id_afil_viejo;
in mysql documentation I can run SELECT id, data INTO @x, @y FROM test.t1 LIMIT 1;
.
Is the problem in the use of the FETCH
? or What is the problem?