If you are familiar with collection types in other languages the following terminology matrix can help you decide which PL/SQL collection type is appropriate for your code.
Other Languages | PL/SQL |
---|---|
Array | Varray |
Bag | Nested Table |
Set | Nested Table |
Hash Table | Associative Array |
Unordered Lookup Table | Associative Array |
The next table presents operational characteristics of each collection type.
Characteristic | Associative Array | Nested Table | Varray |
---|---|---|---|
The entire collection can be saved in a database column. | Y | Y | |
Rows in the collection retain their order when the entire collection is saved in a database column. | n/a | Y | |
Legal subscript datatypes. | any | Integer | Integer |
Legal subscript value ranges. | -2**31..2**31 (for Integers) |
1..2**31 | 1..2**31 |
The collection can be defined to hold a predefined maximum number of rows. | Y | ||
There can be gaps between subscripts, e.g. 1,3,8. | Y | Y | |
The collection must be initialized before used. | Y | Y | |
The collection can be initialized with multiple rows of data using a single command (i.e. a constructor). | Y | Y | |
The collection must be extended before a new row is added. | Y | Y | |
Two collections can be compared for equality with the "=" operator. | Y | ||
The collection can be manipulated in PL/SQL with MULTISET Operators e.g. MULTISET UNION, MULTISET INTERSECT. | Y | ||
The collection can be unnested in a query using the TABLE() collection expression. | Y | Y |