HOW-TO use PL/SQL Table
set serveroutput on
begin
-- Declare the PL/SQL table
declare
type deptarr is table of dept%rowtype index by binary_integer;
d_arr deptarr;
type deptarr1 is table of dept.deptno%type;
type deptarr2 is table of dept.dname%type;
type deptarr3 is table of dept.loc%type;
v_deptno deptarr1;
v_dname deptarr2;
v_loc deptarr3;
type deptarr10 is table of dept.deptno%type;
type deptarr20 is table of dept.dname%type;
type deptarr30 is table of dept.loc%type;
v_deptno10 deptarr10;
v_dname20 deptarr20;
v_loc30 deptarr30;
-- Declare cursor
type d_cur is ref cursor return dept%rowtype;
c1 d_cur;
i number := 1;
begin
select deptno,dname,loc bulk collect
into v_deptno,v_dname,v_loc
from dept;
-- Populate the PL/SQL table from the cursor
open c1 for select * from dept;
fetch c1 bulk collect into v_deptno10,v_dname20,v_loc30;
-- loop
-- exit when c1%NOTFOUND;
-- fetch c1 bulk collect into d_arr(i);
-- i := i+1;
-- end loop;
close c1;
-- Display the entire PL/SQL table on screen
--for i in 1..d_arr.last loop
for i in 1..v_deptno.last loop
dbms_output.put_line('DEPTNO1 : '||v_deptno(i));
dbms_output.put_line('DNAME1 : '||v_dname(i));
dbms_output.put_line('LOC1 : '||v_loc(i));
dbms_output.put_line('DEPTNO10 : '||v_deptno10(i));
dbms_output.put_line('DNAME20 : '||v_dname20(i));
dbms_output.put_line('LOC30 : '||v_loc30(i));
---dbms_output.put_line('DEPTNO : '||d_arr(i).deptno );
---dbms_output.put_line('DNAME : '||d_arr(i).dname );
---dbms_output.put_line('LOC : '||d_arr(i).loc );
dbms_output.put_line('---------------------------');
end loop;
end;
end;
/
0 Comments:
Post a Comment
<< Home