Saturday, 23 August 2014

Use of loops in MySQL stored procedures

Loops -> Repetitive tasks

3 types of loops in MySQL stored program:
- Simple loop using LOOP and END LOOP clauses
- WHILE and END WHILE clauses that runs while a condition is true
- REPEAT and UNTIL clauses that runs until a condition is true

Termination of loop -> LEAVE statement.
I will demonstrate the use of loops the simple loop way.

Explaining simply, we are defining a counter that starts with 0 and a LOOPlabelled my_loop that increments from 0 onward and a condition inside to check for counter value of 10, when the loop terminates through the use of LEAVE clause. You can give a try to the other loop clauses :)