Comparatie Tipuri de Colectii
Comparatie Tipuri de Colectii
Comparatie Tipuri de Colectii
Varray is a collection method in which the size of the array is fixed. The array size
cannot be exceeded than its fixed value. The subscript of the Varray is of a numeric
value. Following are the attributes of Varrays.
· Upper limit size is fixed
· Populated sequentially starting with the subscript '1'
· This collection type is always dense, i.e. we cannot delete any array
elements. Varray can be deleted as a whole, or it can be trimmed from the
end.
· Since it always is dense in nature, it has very less flexibility.
· It is more appropriate to use when the array size is known and to perform
similar activities on all the array elements.
· The subscript and sequence always remain stable, i.e. the subscript and
count of the collection is always same.
· They need to be initialized before using them in programs. Any operation
(except EXISTS operation) on an uninitialized collection will throw an
error.
· It can be created as a database object, which is visible throughout the
database or inside the subprogram, which can be used only in that
subprogram.
· The one big advantage of VArrays over nested tables is that they guarantee the
order of the elements. So if you must get elements out in the same order as you
inserted them use a VArray.
·
The below figure will explain the memory allocation of Varray (dense)
diagrammatically.
Subscri 1 2 3 4 5 6 7
pt
Value Xyz Dfv Sde Cxs Vbc Nhu Qwe
Syntax for VARRAY:
TYPE <type_name> IS VARRAY (<SIZE>) OF <DATA_TYPE>;
Nested Tables
A Nested table is a collection in which the size of the array is not fixed. It has the
numeric subscript type. Below are more descriptions about nested table type.
· The Nested table has no upper size limit.
· Since the upper size limit is not fixed, the collection, memory needs to be
extended each time before we use it. We can extend the collection using
'EXTEND' keyword.
· Populated sequentially starting with the subscript '1'.
· This collection type can be of both dense and sparse, i.e. we can create the
collection as a dense, and we can also delete the individual array element
randomly, which make it as sparse.
· It gives more flexibility regarding deleting the array element.
· It is stored in the system generated database table and can be used in the
select query to fetch the values.
· The subscript and sequence are not stable, i.e. the subscript and the count of
the array element can vary.
· They need to be initialized before using them in programs. Any operation
(except EXISTS operation) on the uninitialized collection will throw an
error.
· It can be created as a database object, which is visible throughout the
database or inside the subprogram, which can be used only in that
subprogram.
The below figure will explain the memory allocation of Nested Table (dense and
sparse) diagrammatically. The black colored element space denotes the empty
element in a collection i.e. sparse.
Subscri 1 2 3 4 5 6 7
pt
Value Xyz Dfv Sde Cxs Vbc Nhu Qwe
(dense)
Value(s Qwe Asd Afg Asd Wer
parse)
Syntax for Nested Table:
TYPE <tvpe name> IS TABLE OF <DATA TYPE>;
Index-by-table
Index-by-table is a collection in which the array size is not fixed. Unlike the other
collection types, in the index-by-table collection the subscript can consist be
defined by the user. Following are the attributes of index-by-table.
· The subscript can of integer or strings. At the time of creating the collection,
the subscript type should be mentioned.
· These collections are not stored sequentially.
· They are always sparse in nature.
· The array size is not fixed.
· They cannot be stored in the database column. They shall be created and
used in any program in that particular session.
· They give more flexibility in terms of maintaining subscript.
· The subscripts can be of negative subscript sequence also.
· They are more appropriate to use for relatively smaller collective values in
which the collection can be initialized and used within the same
subprograms.
· They need not be initialized before start using them.
· It cannot be created as a database object. It can only be created inside the
subprogram, which can be used only in that subprogram.
· BULK COLLECT cannot be used in this collection type as the subscript
should be given explicitly for each record in the collection.
The below figure will explain the memory allocation of Nested Table (sparse)
diagrammatically. The black colored element space denotes the empty element in a
collection i.e. sparse.
Subscri FIRST SECON THIRD FOURT FIFTH SIXTH SEVEN
pt D H TH
(varchar
)
Value(s Qwe Asd Afg Asd Wer
parse)
Syntax for Index-by-Table
TYPE <type_name> IS TABLE OF <DATA_TYPE> INDEX BY VARCHAR2 (10);