ITERATE is a flow-control statement available in MySQL, MariaDB, IBM DB2, and a few other SQL/PSM-compatible systems. It can only appear inside stored programs (procedures, functions, triggers, or events) and must reference the label of the loop it controls. When the statement executes, the interpreter:1. Checks that the referenced label belongs to an active LOOP, WHILE, or REPEAT block.2. Abandons all statements that remain in the current iteration after the ITERATE call.3. Transfers control to the loop’s test condition. If the condition still evaluates to TRUE, the next iteration begins; otherwise the loop ends.ITERATE behaves like the continue keyword in many general-purpose languages. It does not exit the loop (use LEAVE for that) and it cannot target outer blocks that are not loops. Only one label is allowed, and it must be written exactly as declared (case-sensitive on case-sensitive servers).
- loop_label
(identifier) - Name of the LOOP, WHILE, or REPEAT block whose next iteration should start.LEAVE, LOOP, WHILE, REPEAT, CONTINUE (PL/pgSQL), BREAK
MySQL 5.0 (2005) and IBM DB2 UDB 7.1
ITERATE restarts the current labeled loop by skipping all remaining statements in its body and reevaluating the loop condition.
Use ITERATE when you want to continue looping but ignore the rest of the current iteration. Use LEAVE when you want to exit the loop completely.
Yes. Place unique labels on each loop. ITERATE can only target an active loop label, so you can jump from an inner block to an outer loop if you name that outer loop.
Indirectly. If your loop fetches from a cursor, ITERATE skips any follow-up processing for that fetch but keeps the cursor open for the next iteration.