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:

a)

What output was printed on the screen?

b)

How many times was the outer loop executed?

c)

How many times was the inner loop executed?

d)

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

e)

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
EAN: N/A
Year: 2003
Pages: 289

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net