0% found this document useful (0 votes)
30 views3 pages

Collections

The document discusses different ways to use PL/SQL collections like tables, arrays, records, and cursors to bulk collect and process multiple rows of data from database tables. It provides examples of using collections with bulk collect to retrieve all rows from a table, retrieve rows into a collection using a cursor, update rows by iterating through a collection, and using collections to store and process record types.

Uploaded by

Salai Sukumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

Collections

The document discusses different ways to use PL/SQL collections like tables, arrays, records, and cursors to bulk collect and process multiple rows of data from database tables. It provides examples of using collections with bulk collect to retrieve all rows from a table, retrieve rows into a collection using a cursor, update rows by iterating through a collection, and using collections to store and process record types.

Uploaded by

Salai Sukumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

PL/SQL Collections

PL/SQL Table
Select.. Fetch stmt
declare
type vel is table of employees%rowtype;
i vel;
a number;
b number;
begin
a:=dbms_utility.get_time;
select * bulk collect into i from employees;
for x in 1..i.count loop
dbms_output.put_line(i(x).first_name||''||i(x).salary);
end loop;
b:=dbms_utility.get_time;
dbms_output.put_line(a);
dbms_output.put_line(b);
dbms_output.put_line(a-b);
end;
/
PL/SQL Table
With Cursor..Fetch stmt
declare
type vel is table of employees%rowtype;
emp vel;
cursor emp_cur is select * from employees;
a number;
b number;
begin
a:=dbms_utility.get_time;
open emp_cur;
fetch emp_cur bulk collect into emp;
for i in emp.first..emp.last loop
dbms_output.put_line(emp(i).first_name||''||emp(i).salary);
end loop;
b:=dbms_utility.get_time;
dbms_output.put_line(a);
dbms_output.put_line(b);
dbms_output.put_line(a-b);
end;
/
All_objects PL/SQl Table With Cursor
declare
type vel is table of all_objects.object_name%type index by binary_integer;
v1 vel;
cursor emp_cur is select object_name from all_objects;
a number(10);

b number(10);
begin
a:=dbms_utility.get_time;
open emp_cur;
fetch emp_cur bulk collect into v1;
for x in 1..v1.count loop
dbms_output.put_line(v1(x));
end loop;
dbms_output.put_line(v1.count());
b:=dbms_utility.get_time;
dbms_output.put_line(a);
dbms_output.put_line(b);
dbms_output.put_line(a-b);
end;
/
BULK BIND (UPDATE WITH %TYPE)
declare
type vel is table of emp.salary%type index by binary_integer;
v1 vel;
begin
select employee_id bulk collect into v1 from emp;
forall i in v1.first..v1.last
update emp set salary=salary+1000 where employee_id=v1(i);
end;
Varray
declare
type vel is varray(110) of employees%rowtype;
v1 vel:=vel();
begin
select * bulk collect into v1 from employees;
for i in v1.first..v1.last loop
dbms_output.put_line(v1(i).first_name||''||v1(i).last_name);
end loop;
v1.trim(3);
dbms_output.put_line(v1.count);
end;
/
Nested Table
declare
type vel is table of employees%rowtype;
v1 vel:=vel();
begin
select * bulk collect into v1 from employees;
for i in v1.first..v1.last loop
dbms_output.put_line(v1(i).first_name||''||v1(i).last_name);
end loop;

v1.trim(3);
dbms_output.put_line(v1.count);
end;
/
RECORD
declare
type rec is record(name employees.first_name%type,id employees.employee_id
%type);
i rec;
begin
select first_name,employee_id into i from employees
where employee_id=100;
dbms_output.put_line(i.name||''||i.id);
end;
/

You might also like