Cursor in Mysql


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



Copy this code and paste it in your HTML
  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 ;

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.