Sie sind auf Seite 1von 5

Collections:-

(Collection, collections Methods

Collection is combinations multiple data type.

Collection Methods:-very collection type having is methods)

(Pick point execution, complex is reduces)

Collection is combination on multiple Data types.

Oracle Server Support Following types.


1. Pl/Sql Record or Record Type.
2. Index by Table (OR) PL/SQL table Associative Arrays
3. Nested Table
4. Varrays .
5. Ref Cursor.

Index by Table

This is User Define data type is used store multiple data type in to a
Single unit.
Basically this is an unconstraint table.
Generally these tables are used to improve the performance of
Application because these tables are stored in memory area thats why
these tables are also called as memory tables.
Basically these table contains key value pairs ie.value filed is stored in
actual data and key field store in indexes.
Key field values are either integer or character and also these values
are either ve or +ve.
This indexes key behaves like a primary key i.e does not accept
duplicate and null values. Basically this key data type is binary integer.
Index by table having following collection Methods.
1. Exists
2. First
3. Last
4. Prior
5. Next
6. Count
7. Delete (range of indexes)

Ex-1
declare
typet1istableofnumber(10)
indexbybinary_integer;
v_tt1;
begin
v_t(1):=10;
v_t(2):=20;
v_t(3):=30;
v_t(4):=40;
v_t(5):=50;
dbms_output.put_line(v_t(3));
dbms_output.PUT_LINE(v_t.first);
dbms_output.put_line(v_t.last);
dbms_output.put_line(v_t.prior(3));
dbms_output.put_line(v_t.next(4));
dbms_output.put_line(v_t.count);
dbms_output.put_line(v_t.(5));
end;

Ex:-2
declare

type t1 is table of number(10)

index by binary integer;

v_t t1;

begin

v_t(1):=10;

v_t(2):=20;

v_t(3):=30;

v_t(3):=40;

v_t(4):=50;

dmbs_output.put_line(v_t.count);

v_t.delete(2,3);

dbms_output.put_line(v_t.count);

v_t.delete;
dbms_output.put_line(v_t.count);

end;

Ex 3:

Write a PLSQL Program to get all employee names from emp table and store it into
index by table and display data from index by table?

Declare

Type t1 is table of varchar2(10) index by binary_interger;

v_t t1;

cursor c1 is select ename from emp;

n number(50):=1;

begin

open c1;

loop

fetch c1 into v_t(n);

exit when c1%notfound;

n:=n+1;

end loop;

close c1;

for I in v_t.first v_t.last

loop

dmbs_output.put_line(v_t(i));

end loop;

end;

Nested Tables
This is also user define type which is used to store multiple data items in a
single unit but before we are storing actual data we must initialize the
data while using constructor.

Here constructor name is same as type name. generally we are not allow
to store index by table by tables permanently into database to overcome
this problem they are introduce nested table extension of the index by
table

These user define type stored permanently into database using sql

In index by table we can not add or remove the indexes where as in


Nested table we can add or remove the indexes using extened trim
collected methods

In nested tables we can allocated the memory explicity while extend


method.

Type type_name is table of datatype (size);

Variable_name type_name();=>constructor_name;

Varrays

This is alos user define data type it is used to the stored multiple data
item in single unite but before we are storing actual data we must
initialize the data while using constructor.

These user defined type stored permanently into database using sql

Basically we are using the varrays for retrieving the huge data.

Syntax :-

Type type_name is varray (maxsize) of datatype(size);

Variable_name type_name :=type_name();

Program
Declare

Type t1 is varray(50) of emp%rowtype;

V_t1:=t1;

Begine

Select * bulk collect into v from emp;

For I in v.frist..v.last

Loop

Dbms_output.put_line(v(i).empno||,||v(i).ename||,||v(i).job);

End loop;

createtypexxt111istableofvarchar2(200);

End;

Difference b/w Index by Table ,Nested Table,Varrays

Index by table Nested table Varrays


1.It is not stored 1.It is stored 1.It is stored
permanently in permanently in permanently in
database. database by using sql database by using sql.
2.we can not add or 2.we can add or 2.we can add or
remove remove indexes using remove indexes
Indexes. extend trim mentod. Using extend trim
3.Indexes starting form 3.Indexes starting from method
negative to positive 1 Indexes starting from 1
number and also
having key value paires

Das könnte Ihnen auch gefallen