Skip to main content

Choosing a Collection Type

As a PL/SQL developer, I find myself leaning toward using associative arrays as a first instinct. 

Why is this?

  • They involve the least amount of coding.
  • You don't have to initialize or extend them.
  • They have historically been the most efficient collection type (although this distinction will probably fade over time).
However, if you want to store your collection within a database table, you cannot use an associative array.

The question then becomes: nested table or VARRAY?

I have listed down a few guidelines which might help you choose.

  • If you do not intend to store data into database use associative arrays
  • If your PL/SQL application requires negative subscripts, you also have to use associative arrays.
  • If you want to enforce a limit to the number of rows stored in a collection, use VARRAYs.
  • If you intend to store large amounts of persistent data in a column collection, your only option is a nested table. Oracle will then use a separate table behind the scenes to hold the collection data, so you can allow for almost limitless growth.
  • If you want to preserve the order of elements stored in the collection column and if your data-set will be small, use a VARRAY
  • if you want to store your collection within a database table use nested table or varray

Reference :
Oracle PL/SQL programming
 By Steven Feuerstein, Bill Pribyl

Comments