Home » Mysql » For loop example in MySQL

For loop example in MySQL

Posted by: admin April 4, 2018 Leave a comment

Questions:

In MySQL, I have this stored procedure with a For loop in it:

DELIMITER $$  
CREATE PROCEDURE ABC()

   BEGIN
      DECLARE a INT Default 0 ;
      simple_loop: LOOP
         SET a=a+1;
         select a;
         IF a=5 THEN
            LEAVE simple_loop;
         END IF;
   END LOOP simple_loop;
END $$

It always prints 1. What is the correct syntax for a MySQL for loop?

Answers: