In which of the following scenarios would you recommend using associative arrays?
A.
When you want to retrieve an entire row from a table and perform calculations
B.
When you know the number of elements in advance and the elements are usuallyaccessed
sequentially
C.
When you want to create a separate lookup table with multiple entries for each row of the main
table, and access it through join queries
D.
When you want to create a relatively small lookup table, where the collection can be
constructed on memory each time a subprogram is invoked.
D
D
C is incorrect.
Associative arrays cannot be used in queries
d
D
D
An associative array is appropriate for:
A relatively small lookup table, which can be constructed in memory each time you invoke the subprogram or initialize the package that declares it
Passing collections to and from the database server
Declare formal subprogram parameters of associative array types. With Oracle Call Interface (OCI) or an Oracle precompiler, bind the host arrays to the corresponding actual parameters. PL/SQL automatically converts between host arrays and associative arrays indexed by PLS_INTEGER.
An index-by table (also called an associative array) is a set of key-value pairs. Each key is unique and is used to locate the corresponding value. The key can be either an integer or a string.
DECLARE
TYPE salary IS TABLE OF NUMBER INDEX BY VARCHAR2(20);
salary_list salary;
name VARCHAR2(20);
BEGIN
— adding elements to the table
salary_list(‘Rajnish’) := 62000;
salary_list(‘Minakshi’) := 75000;
salary_list(‘Martin’) := 100000;
salary_list(‘James’) := 78000;
— printing the table
name := salary_list.FIRST;
WHILE name IS NOT null LOOP
dbms_output.put_line
(‘Salary of ‘ || name || ‘ is ‘ || TO_CHAR(salary_list(name)));
name := salary_list.NEXT(name);
END LOOP;
END;
/
D
A: PL/SQL records.
B: Varrays.
C:Nested tables.
D: Associated arrays.
Again, one more dumb question from Oracle. If i would want to construct small in-memory table, i would go for Nested Table, not index-by.
D