MySQL Forums
Forum List  »  Spanish

Ayuda cursores
Posted by: Juan García Díaz
Date: April 16, 2014 11:09AM

Hola buen día, estoy utilizando cursores pero tengo un problema resulta que mi cursor obtiene 2 datos pero esta mostrando 3 no se porque, les expongo las cosas con los códigos SQL que tengo:

Tabla asignacion_video (es una tabla referencial)

CREATE TABLE `asignacion_video` (
`id_asignacionvideo` int(4) NOT NULL AUTO_INCREMENT,
`id_ticket` int(4) NOT NULL,
`id_oficialasignado` int(4) NOT NULL,
PRIMARY KEY (`id_asignacionvideo`),
KEY `id_oficialasignado` (`id_oficialasignado`),
CONSTRAINT `asignacion_video_ibfk_1` FOREIGN KEY (`id_oficialasignado`) REFERENCES `usuario` (`id_usuario`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Actualmente no cuenta con un registro, cuando ejecuto mi SP debería de ser llenada, pero repite el ultimo registro.

SP Estructura:

BEGIN
DECLARE done BOOLEAN DEFAULT 0;
DECLARE o,a INT;
DECLARE ordernumbers CURSOR
FOR
SELECT
asignacion_colonia.id_usuario
FROM
asignacion_colonia
INNER JOIN cat_estados AS cae ON asignacion_colonia.id_catestado = cae.id_estados
WHERE
cae.asentamiento LIKE parametro;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done=1;
SET a = ticket;
OPEN ordernumbers;
REPEAT
FETCH ordernumbers INTO o;
CALL save_asignacionvideo(a,o);
UNTIL done END REPEAT;
CLOSE ordernumbers;
END

El resultado que se almacena en el cursor es el siguiente: 1 y 3

+------------+
| id_usuario |
+------------+
| 1 |
| 3 |
+------------+
2 rows in set

Entonces cuando ejecuto el procedimiento mando a llamar un insert en otro procedimiento que es el CALL save_asignacionvideo(a,o);
el cual debería de ingresar en la tabla lo siguiente

+--------------------+-----------+--------------------+
| id_asignacionvideo | id_ticket | id_oficialasignado |
+--------------------+-----------+--------------------+
| 1 | 1 | 1 |
| 2 | 1 | 3 |
+--------------------+-----------+--------------------+
Pero esta haciendo lo siguiente

+--------------------+-----------+--------------------+
| id_asignacionvideo | id_ticket | id_oficialasignado |
+--------------------+-----------+--------------------+
| 1 | 1 | 1 |
| 2 | 1 | 3 |
| 3 | 1 | 3 |
+--------------------+-----------+--------------------+
3 rows in set

lo cual no es lo correcto, espero y me puedan ayudar.

Saludos.

Options: ReplyQuote


Subject
Views
Written By
Posted
Ayuda cursores
2093
April 16, 2014 11:09AM
964
April 17, 2014 08:28AM


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.