Professional Documents
Culture Documents
When To Use What?: Varray
When To Use What?: Varray
Varray
1.
2.
3.
whole
Nested Table
1.
2.
Use when working with an unbounded list that needs to increase dynamically
Use when you need to store in the database and operate on elements
individually
Associative Array
1.
Use when there is no need to store the Collection in the database. Its speed and
indexing flexibility make it ideal for internal application use.
Associative Array
Associative arrays are a set of key value pairs where each key is unique and is used to
locate the corresponding value in the array. The key can be integer or a string.
DECLARE -- Associative array indexed by string:
TYPE population IS TABLE OF NUMBER
INDEX BY VARCHAR2(64);
city_population
population;
DECLARE
-- Associative array indexed by integer
TYPE sum_multiples IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER;
n PLS_INTEGER := 5;
-- number of multiples to sum for display
sn PLS_INTEGER := 10; -- number of multiples to sum
m PLS_INTEGER := 3;
-- multiple
Varrays
The Varray is short for Variable Array. A Varray stores elements of the same type in the
order in which they are added. The number of elements in a Varray must be known at
the time of its declaration. In other words, a Varray has fixed lower and upper bounds,
making it most similar to collection types from other programming languages. Once it is
created and populated, each element can be accessed by a numeric index.
DECLARE
TYPE Foursome IS VARRAY(4) OF VARCHAR2(15);
-- VARRAY type
Nested Table
Nested Tables, like the Varray, can be stored in a relational table as well as function as a
PL/SQL program variable. Unlike Varray, nested tables require no size specification. In
other words, they are unbound.