Friday, 26 February 2016

PL/SQL ASSOCIATED ARRAY(PAA):


  • It is a PL/SQL Associative Array,which is used to store a set of elements for records.In general we can access data from the cursor only at once and it does not allow reverse fetching.
  • By using a PAA we can overcome the disadvantage of a cursor.
  • We can access the Data from a PAA variable for multiple times and we can access the Data in any order(forward/backward).


SYNTAX:
type  <type_name>  is table 
of   <data_type>(size)/<anchor datatype>
index by Binary_Integer/Pls_Integer;

EXAMPLE:
type num_type is table of number(5)
index by Binary_Integer;

ATTRIBUTES OF PAA:
1.<PAA var>.First:This attribute is used to get a first index of a PAA variable.
2.<PAA var>.Last:This attribute is used to get a last index of a PAA variable.
3.<PAA var>.NEXT(Int):This attribute is used to get the next index of PAA variable.
4.<PAA var>.Count:ToCount all the values in a PAA variable.
5.<PAA var>.DELETE(int,int): It is used to delete all the elements of a PAA variable.

NOTE:A Binary_Integer datatype will convert the Data into binary format & it will work more faster than number datatype.
A Pls_Integer datatype will conversts the data into ALU understandable format,it will work more faster than Binary_Integer datatype.

EXAMPLE:
DECLARE
type  emp_type is table of emp%rowtype
index by binary_integer;
emp1 emp_type;
cursor  c is select * from emp;
begin
for i in c lopp
emp1(c%rowcount):=i;
end loop;
for i in reverse emp1.first..emp1.last
loop
dbms_output,put_line(emp1(i).empno||' '||emp1(i).ename||' '||emp1(i).sal||' '||emp1(i).job);
end loop;
dbms_output.put_line(emp1.count||'records are available');
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.