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 7

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


RF

RF

Associative arrays let you insert elements using arbitrary key values. The keys need not be consecutive.

The key data type can be PLS_INTEGER, VARCHAR2, or one of VARCHAR2 subtypes VARCHAR, STRING, or LONG.

You must specify the length of a VARCHAR2-based key, except for LONG which is equivalent to declaring a key type of VARCHAR2(32760). The types RAW, LONG RAW, ROWID, CHAR, and CHARACTER are not allowed as keys for an associative array. The LONG and LONG RAW data types are supported only for backward compatibility; see LONG and LONG RAW Data Types for more information.

An initialization clause is not allowed. There is no constructor notation for associative arrays. When you reference an element of an associative array that uses a VARCHAR2-based key, you can use other types, such as DATE or TIMESTAMP, as long as they can be converted to VARCHAR2 with the TO_CHAR function.

PIERO

PIERO

CREATE TABLE HR.DEPARTMENTS
(
DEPARTMENT_ID NUMBER(4),
DEPARTMENT_NAME VARCHAR2(30 BYTE) CONSTRAINT DEPT_NAME_NN NOT NULL,
MANAGER_ID NUMBER(6),
LOCATION_ID NUMBER(4),
MAIN_PHONE VARCHAR2(20 BYTE),
TITLE VARCHAR2(80 BYTE)
)

TYPE tb1 IS TABLE OF departments.department_name%TYPE INDEX BY NUMBER;
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);

ALL associative array … index by
not RAW, LONG RAW, ROWID, CHAR, and CHARACTER and
let you insert elements using arbitrary key values.

PIERO

PIERO

OPS

B,C

DECLARE
TYPE tb1 IS TABLE OF departments.department_name%TYPE INDEX BY NUMBER(4);
TYPE tb4 IS TABLE OF DATE INDEX BY DATE;
TYPE tb5 IS TABLE OF NUMBER INDEX BY CHAR(2);
BEGIN
NULL;
END;
ORA-06550: riga 2, colonna 13:
PLS-00315: Restrizione di implementazione: tipo di indice di tabella non supportato.
ORA-06550: riga 2, colonna 1:
PL/SQL: Item ignored
ORA-06550: riga 3, colonna 13:
PLS-00315: Restrizione di implementazione: tipo di indice di tabella non supportato.
ORA-06550: riga 3, colonna 1:
PL/SQL: Item ignored
ORA-06550: riga 4, colonna 13:
PLS-00315: Restrizione di implementazione: tipo di indice di tabella non supportato.
ORA-06550: riga 4, colonna 1:
PL/SQL: Item ignored

Carlos Castaneda

Carlos Castaneda

PIERO!
Such a stupid moron…
Think then write, don’t write then think.