COLLECTION:
A Collection is an Ordered group of elements having the same data type.
EXAMPLE:Marks of the Students of a particular class.
Collections are just like ordinary data type and they can be passed as parameter PL/SQL provide two types of collections i.,VARRAY & NESTED TABLES.
A Collection is an Ordered group of elements having the same data type.
EXAMPLE:Marks of the Students of a particular class.
Collections are just like ordinary data type and they can be passed as parameter PL/SQL provide two types of collections i.,VARRAY & NESTED TABLES.
- VARRAY is like an Array in programming language dimension.
- NESTED TABLES are also like an array having single dimension but with no upper limit.
- A VARRAY is data type very similar to an Array.
- A VARRAY has a fixed limitation its size specified part of the Declaration.
- Elements are Inserted into VARRAY at Index 1,upto max length declared in the VAARAY type.
- The Maximum size of the VAARAY is 2Giga Bytes.
The First Difference between VARRAY & NESTED TABLES is that there is fixed upper bound for VARRAY & whereas NESTED TABLE there is no fixed UPPER BOUND.So theoretically we can store unlimited values in nested tables.
The Second Difference between VARRAY & NESTED TABLES is VARRAY is SPARSE(cannot delete any individual element from VARRAY).whereas NESTED TABLES is DENSE(can delete any individual element from the Table.)Once we delete any element from table it becomes SPARSE. If VARRAY is the column of the Table then the data of VARRAY is stored along with the record of the Table. This type of storage can be called as 'DATA OUT OF LINE'.
SYNTAX OF VARRAY:
type <VARRAY_NAME> is VARRAY(upper bound value) of <data type>;
SYNTAX OF NESTED TABLES:
type <NESTED TABLE_NAME> is table of <data type>;
Example on VARRAY:
DECLARE
TYPE A IS VARRAY(10) OF NUMBER;
X A; --x is a variable of 'a' type which is VARRAY.
BEGIN
X:=A(10,20,11,22,89,56,59,58,44,33);
/*HERE A IS A CONSTRUCT METHOD WHICH IS USED TO ASSIGN THE ELEMENTS OF THE ARRAY.CONSTRUCTOR NAME AND DATA TYPE NAME MUST BE SAME*/
FOR I IN 1..X.COUNT
LOOP
DBMS_OUTPUT.PUT_LINE(X(I));
END LOOP;
END;
No comments:
Post a Comment
If you Like my blog Spread it and help friends for whom this blog is useful for their career.