Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/09/2011, 02:55
SadlyMistaken
 
Fecha de Ingreso: febrero-2007
Mensajes: 13
Antigüedad: 17 años, 2 meses
Puntos: 0
¿Por qué me da fallo este cursor?

Hola, buenas a todos, me estoy volviendo loco con este cursor... me da este fallo:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE cursor_ediciones CURSOR FOR SELECT id_edicion FROM EDICIONES_TAB WHERE i...'




Código:
DELIMITER $$

DROP PROCEDURE IF EXISTS `OLEMANIA`.`insertar_historietas_en_vinculaciones`$$
CREATE PROCEDURE `OLEMANIA`.`insertar_historietas_en_vinculaciones` (IN valor_historia INT(6), IN valor_num INT(3), IN valor_orden VARCHAR(4))
BEGIN

INSERT INTO VINC_SENCILLA_TAB (id_historia, id_num, orden_en_ole) 
VALUES (valor_historia, valor_num, valor_orden);
SET @variable := LAST_INSERT_ID();

DECLARE sin_registros INT DEFAULT 0;
DECLARE cursor_ediciones CURSOR FOR SELECT id_edicion FROM EDICIONES_TAB WHERE id_numero = valor_num;
DECLARE CONTINUE HANDLER ya_no_hay FOR NOT FOUND SET sin_registros=1;

OPEN cursor_ediciones;

REPEAT
FETCH cursor_ediciones INTO valor_encontrado;
INSERT INTO id_vs, id_e, esta VALUES (@variable, valor_encontrado, '??');
UNTIL ya_no_hay END REPEAT;

CLOSE cursor_ediciones;

END$$

DELIMITER ;
Espero puedan ayudarme, no sé que estoy haciendo mal... Uso MYSQL 5.1.49