Chapter 18 Collections

1)Create the following script. Create an index-by table and populate it with the instructor’s full name. In other words, each row of the index-by table should contain first name, middle initial, and last name. Display this information on the screen.
A1: Answer: Your script should look similar to the following:
SET SERVEROUTPUT ON 
DECLARE 
   CURSOR name_cur IS 
      SELECT first_name||' '||last_name name 
        FROM instructor; 

   TYPE name_type IS TABLE OF VARCHAR2(50) 
      INDEX BY BINARY_INTEGER; 
   name_tab name_type; 

   v_counter INTEGER := 0; 
BEGIN 
   FOR name_rec IN name_cur LOOP 
      v_counter := v_counter + 1; 
      name_tab(v_counter) := name_rec.name; 

      DBMS_OUTPUT.PUT_LINE ('name('||v_counter||'): '|| 
         name_tab(v_counter)); 
   END LOOP; 
END; 

In the preceding ...

Get Oracle® PL/SQL® Interactive Workbook, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.