O'Reilly logo

Oracle® PL/SQL® Interactive Workbook, Second Edition by Elena Silvestrova, Benjamin Rosenzweig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lab 8.4 Nested Loops

Lab Objectives

After this Lab, you will be able to:

Use Nested Loops

You have explored three types of loops: simple loops, WHILE loops, and numeric FOR loops. Any of these three types of loops can be nested inside one another. For example, a simple loop can be nested inside a WHILE loop and vice versa. Consider the following example:

FOR EXAMPLE

DECLARE 
   v_counter1 INTEGER := 0; 
   v_counter2 INTEGER; 
BEGIN 
   WHILE v_counter1 < 3 LOOP 
      DBMS_OUTPUT.PUT_LINE ('v_counter1: '||v_counter1); 
      v_counter2 := 0; 
      LOOP
					DBMS_OUTPUT.PUT_LINE ('v_counter2: '||v_counter2);
					v_counter2 := v_counter2 + 1;
					EXIT WHEN v_counter2 >= 2;
					END LOOP; 
      v_counter1 := v_counter1 + 1; 
   END LOOP; 
END; 

In this example, the WHILE loop is called an outer loop ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required