Searching for "types."

Q:

What is a Collection? Explain collection types.

Answer

A collection just like an array is an ordered group of elements of the same type. Each elements position is determined by a unique subscript.


 


Index by tables:- They are similar to hash arrays that allows to search for subscript values using arbitrary numbers and strings.


They can be declared as:


TYPE type_name IS TABLE OF element_type [NOT NULL]


INDEX BY [BINARY_INTEGER | PLS_INTEGER | VARCHAR2(size_limit)];


INDEX BY key_type;


Example:


TYPE studenttyp IS TABLE OF emp%ROWTYPE


INDEX BY BINARY_INTEGER;


stud_tab studenttyp;


 


Nested tables:- they hold random number of elements and use sequential numbers as sub scripts.


They can be declared as:


TYPE type_name IS TABLE OF element_type [NOT NULL];


Example: TYPE employee_type IS TABLE OF NUMBER INDEX BY VARCHAR2(64);


 


Varrays: Holds a fixed number of elements which can be changed in run time. 


They can be declared as:


TYPE type_name IS {VARRAY | VARYING ARRAY} (size_limit) OF element_type [NOT NULL];


Example: TYPE Calendar IS VARRAY(366) OF DATE;

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle