Manejo de Cursores en SP en MYSQL


/ Published in: MySQL
Save to your folder(s)

Esquema basico de manejo de cursores en MYSQL


Copy this code and paste it in your HTML
  1. CREATE DEFINER=`root`@`localhost` PROCEDURE `myprocedure`()
  2.  
  3. DECLARE done BOOLEAN DEFAULT FALSE; -- VARIABLE DE CONTROL
  4. DECLARE c1 CURSOR FOR /* SENTENCIA SQL */; -- DECLARACION CURSOR
  5. DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE; -- MANEJADOR EVENTOS
  6.  
  7. OPEN c1; //ABRIMOS EL CURSOR
  8. c1_loop: LOOP FETCH c1 INTO /* AQUI VARIABLES QUE TOMAN EL VALOR DE CURSOR*/;
  9. IF `done` THEN LEAVE c1_loop; END IF; // FINALIZA EL CICLO SI EL EVENTO INDICA QUE NO HAY REGISTROS
  10. -- AQUI SENTENCIAS INTERNAS AL CICLO
  11. END LOOP c1_loop; // LOOP CURSOR
  12. CLOSE c1; // CERRAMOS CURSOR
  13.  
  14.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.