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

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 ...

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