Posted By

georgemathewkunnathoor on 08/19/11


Tagged

mysql Cursors


Versions (?)

Cursor in Mysql


 / Published in: SQL
 

URL: http://www.gladsys.in/blog/stored-procedures-in-mysql/

  1. DROP procedure IF EXISTS cur_movie;
  2.  
  3. delimiter //
  4.  
  5.  
  6. CREATE procedure cur_movie()
  7. begin
  8. declare mname varchar(100);
  9. declare yr int;
  10. declare flag int DEFAULT 0;
  11. declare c cursor FOR SELECT movie_name,release_year FROM movie;
  12. declare exit handler FOR NOT found SET flag=1;
  13. open c;
  14.  
  15. fetch c INTO mname, yr;
  16.  
  17. loop
  18. SELECT mname AS MovieName ,yr AS ReleaseYear;
  19. fetch c INTO mname,yr;
  20.  
  21. end loop;
  22. close c;
  23.  
  24. end //
  25. delimiter ;

Report this snippet  

You need to login to post a comment.