loop

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

loop [2015/09/23 20:27] (current)
Line 1: Line 1:
 +====== LOOP Statement - PL/HQL Reference ======
 +
 +LOOP statement executes one or more statements until you exit the loop using EXIT, LEAVE or BREAK statements, or raising an exception. ​
 +
 +Syntax:
 +
 +<code language=sql>​
 +[<<​label>>​ | label:]
 +LOOP
 +  statements
 +END LOOP;
 +</​code>​
 +
 +**Examples:​**
 +
 +<code language=sql>​
 +-- Oracle, PostgreSQL, Netezza
 +LOOP
 +  count := count - 1;
 +  EXIT WHEN count = 0;
 +END LOOP;
 +</​code>​
 +
 +<code language=sql>​
 +-- DB2, Teradata, MySQL
 +lbl:
 +LOOP
 +  SET count = count - 1;
 +  IF count = 0 THEN
 +    LEAVE lbl;
 +  END IF;
 +END LOOP;
 +</​code>​
 +
 +**Compatibility:​** Oracle, Teradata, IBM DB2, MySQL, PostgreSQL and Netezza.