Difference Between Collections

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

The following collection methods help generalize code, make collections easier to use,

and make your applications easier to maintain:

EXISTS
COUNT
LIMIT : For nested tables, which have no maximum size, LIMIT returns NULL
FIRST and LAST : smallest and largest index numbers in a collection.
PRIOR and NEXT :
EXTEND
TRIM
DELETE

Collection method is a built-in function or procedure that operates on collections and is


called using dot notation. The syntax follows:

collection_name.method_name[(parameters)]

Collection methods cannot be called from SQL statements.

Also, EXTEND and TRIM cannot be used with index-by tables. EXISTS, COUNT, LIMIT,
FIRST, LAST, PRIOR, and NEXT are functions; EXTEND, TRIM, and DELETE are procedures.
EXISTS, PRIOR, NEXT, TRIM, EXTEND, and DELETE take integer parameters.

Only EXISTS can be applied to atomically null collections. If you apply another method
to such collections, PL/SQL raises COLLECTION_IS_NULL.
Difference between Nested Table and Index By Table :-

1) Nested tables can be stored in a database column but Index-by tables cannot.
2) Size of Index-by table is unconstrained (Table size grows as the rows are added
to the table) But to extend a nested table, you must use the built-in procedure
EXTEND.
3) The built-in procedure TRIM can be applied to Nested tables But cannot be
applied to Index-by tables.
4) Uninitialized nested table is atomically null (that is, the table itself is null, not its
elements), but an Uninitialized index-by table is merely empty. So, you can apply the
IS NULL comparison operator to nested tables but not to index-by tables.

Varrays versus Nested Tables:-

Nested tables differ from varrays in the following ways:

Varrays have a maximum size, but nested tables do not.


Varrays are always dense, but nested tables can be sparse. So, you can delete
individual elements from a nested table but not from a varray.
When stored in the database, varrays retain their ordering and subscripts,
but nested tables do not
Oracle stores varray data in-line (in the same table) unless it exceeds 4K, in
which case the data is stored out-of-line (but in the same tablespace). But,
Oracle stores nested table data out-of-line in a store table, which is a system-
generated database table associated with the nested table.

You might also like