Lab 8.4 Exercises

8.4.1 Use Nested Loops

In this exercise, you will use nested numeric FOR loops.

Create the following PL/SQL script:

 -- ch08_6a.sql, version 1.0 SET SERVEROUTPUT ON DECLARE    v_test NUMBER := 0; BEGIN    <<outer_loop>>    FOR i IN 1..3 LOOP       DBMS_OUTPUT.PUT_LINE('Outer Loop');       DBMS_OUTPUT.PUT_LINE('i = 'i);       DBMS_OUTPUT.PUT_LINE('v_test = 'v_test);       v_test := v_test + 1;       <<inner_loop>>       FOR j IN 1..2 LOOP          DBMS_OUTPUT.PUT_LINE('Inner Loop');          DBMS_OUTPUT.PUT_LINE('j = 'j);          DBMS_OUTPUT.PUT_LINE('i = 'i);          DBMS_OUTPUT.PUT_LINE('v_test = 'v_test);       END LOOP inner_loop;    END LOOP outer_loop; END; 

Execute the script, and then answer the following questions:


What output was printed on the screen?


How many times was the outer loop executed?


How many times was the inner loop executed?


What are the values of the loop counters, i and j, after both loops terminate?


Rewrite this script using the REVERSE option for both loops. How many times will each loop be executed in this case?

Oracle PL[s]SQL by Example
Oracle PL[s]SQL by Example
ISBN: 3642256902
Year: 2003
Pages: 289 © 2008-2017.
If you may any questions please contact us: