Using Explicit Cursors  «Prev 

FOR loop Cursor Block

FOR loop cursor block
DECLARE
CURSOR order_products IS
  SELECT product_name,
  current_inventory_count
  FROM PRODUCT
  WHERE current_inventory_count<10;
BEGIN
FOR get_products IN order_products LOOP
  DBMS_OUTPUT.PUT_LINE(get_products.product_name
  ||; has to be reordered;);
end loop;
end;
FOR loop cursor block

Oracle PL/SQL Programming
FOR get_products IN order_products LOOP
The FOR loop eliminates the use of OPEN, FETCH, and CLOSE statements. It also eliminates the declaration of the variables for fetching the data. The FOR loop index get_products is implicitly declared as a record.
get_products.product_name

Dot notation is used to reference the product_name column within the cursor.

Simple FOR loops iterate over a specified range of integers (lower_bound .. upper_bound). The number of iterations is known before the loop is entered. The range is evaluated when the FOR loop is first entered and is never re-evaluated.
If lower_ bound equals upper_bound, the loop body is executed once. As Example 6 shows, the sequence of statements is executed once for each integer in the range 1 to 500. After each iteration, the loop counter is incremented.

Example 6: Simple FOR-LOOP Statement

SQL> BEGIN
2 	FOR i IN 1..3 LOOP
3 		DBMS_OUTPUT.PUT_LINE (TO_CHAR(i));
4 	END LOOP;
5 	END;
6 /
PL/SQL procedure successfully completed.
SQL>