Loop Statements

Loop statements are used to process numerous items of data until a specified finish clause is reached – these include CURSOR FOR LOOPS but can also be a simple LOOP with EXIT clause.

Syntax

LOOP
;
EXIT ;

END LOOP;

Example

There a few examples to show which basically do the same work.

STANDARD LOOP
LOOP
v_loop_counter := l_loop_counter + 1;
EXIT WHEN l_loop_counter = 100;
END LOOP;

FOR LOOP (do not confuse with CURSOR FOR LOOP)
FOR l_loop_counter IN 1 .. 100
LOOP
l_loop_counter := l_loop_counter + 1;
END LOOP;

WHILE LOOP
WHILE l_loop_counter <= 100
LOOP
l_loop_counter := l_loop_counter + 1;
END LOOP;

Leave a Reply

Your email address will not be published. Required fields are marked *