Prentice Hall Oracle Plsql By Example 3Rd Edition [Electronic resources]

Benjamin Rosenzweig

نسخه متنی -صفحه : 289/ 208
نمايش فراداده

Lab 18.3 Exercises

18.3.1 Use Multilevel Collections

In this exercise, you will learn more about multilevel collections.

Create the following PL/SQL script:

-- ch18_4a.sql, version 1.0 SET SERVEROUTPUT ON DECLARE TYPE table_type1 IS TABLE OF integer INDEX BY BINARY_INTEGER; TYPE table_type2 IS TABLE OF table_type1 INDEX BY BINARY_INTEGER; table_tab1 table_type1; table_tab2 table_type2; BEGIN FOR i IN 1..2 LOOP FOR j IN 1..3 LOOP IF i = 1 THEN table_tab1(j) := j; ELSE table_tab1(j) := 4 - j; END IF; table_tab2(i)(j) := table_tab1(j); DBMS_OUTPUT.PUT_LINE ('table_tab2('||i||')('||j||'): '||table_tab2(i)(j)); END LOOP; END LOOP; END;

Execute the script, and then answer the following questions:

a)

Execute the script ch18_4a.sql and explain the output produced.

b)

Modify the script so that instead of using multilevel index-by tables it uses a nested table of index-by tables.

c)

Modify the script so that instead of using multilevel index-by tables it uses a nested table of varrays.