Which of the above are valid definitions for associative arrays?

Examine the code snippet from the declarative section of a PL/SQL block:

DECLARE
TYPE va1 IS VARRAY(10) OF VARCHAR2(20);
SUBTYPE scale IS NUMBER(1,0);
TYPE tb1 IS TABLE OF departments.department_name%TYPE INDEX BY
departments.department_id%TYPE;
TYPE tb2 IS TABLE OF va1 INDEX BY PLS_INTEGER;
TYPE tb3 IS TABLE OF scale INDEX BY VARCHAR2(10);
TYPE tb4 IS TABLE OF DATE INDEX BY DATE;
TYPE tb5 IS TABLE OF NUMBER INDEX BY CHAR(2);
….
Which of the above are valid definitions for associative arrays? (Choose all that apply.)

Examine the code snippet from the declarative section of a PL/SQL block:

DECLARE
TYPE va1 IS VARRAY(10) OF VARCHAR2(20);
SUBTYPE scale IS NUMBER(1,0);
TYPE tb1 IS TABLE OF departments.department_name%TYPE INDEX BY
departments.department_id%TYPE;
TYPE tb2 IS TABLE OF va1 INDEX BY PLS_INTEGER;
TYPE tb3 IS TABLE OF scale INDEX BY VARCHAR2(10);
TYPE tb4 IS TABLE OF DATE INDEX BY DATE;
TYPE tb5 IS TABLE OF NUMBER INDEX BY CHAR(2);
….
Which of the above are valid definitions for associative arrays? (Choose all that apply.)

A.
tb1

B.
tb2

C.
tb3

D.
tb4

E.
tb5



Leave a Reply 5

Your email address will not be published. Required fields are marked *


Leo Yu

Leo Yu

tb5 is incorrect:

http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/composites.htm#LNPLS99927

Indexes of Data Types Other Than VARCHAR2
In the declaration of an associative array indexed by string, the string type must be VARCHAR2 or one of its subtypes. However, you can populate the associative array with indexes of any data type that the TO_CHAR function can convert to VARCHAR2. (For information about TO_CHAR, see Oracle Database SQL Language Reference.)

Help: tb1 might be correct if departmet_id%TYPE is PLS_INTEGER or BINERY_INTEGER?

Roscoe

Roscoe

Database column can’t be of PLS_INTEGER or BINARY_INTEGER datatypes. So A is incorrect. The answers are B and C.

fabio

fabio

Yes Roscoe but can be VARCHAR2, that is a valid type for index.
So without the definition of departments.department_id%TYPE; you cannot say if A is correct or no.