Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Nested FORALL

24954Sep 13 2006 — edited Sep 13 2006
Hello to All,

First I create Two Tables

Create Table Dept2 as Select * from Dept where 1 = 2;

Create Table Emp2 As Select emp.*,Dept.Dname From EMp , Dept
Where emp.deptno = Dept.deptno
and 1 = 2;

And Try to Learn Bulk Cokkect and Forall But,
Why the below code not work?

Declare

TYPE Dept_Rec IS RECORD
(
D_num dbms_sql.number_table,
D_name dbms_sql.varchar2_table
);

D_rec Dept_Rec;

TYPE Emp_Rec IS RECORD
(
E_num dbms_sql.number_table,
e_name dbms_sql.varchar2_table
);

e_rec emp_rec;

Cursor c1 is select deptno, dname from dept;

CURSOR c2(DNUM D_Rec.D_num%type) IS SELECT empno,ename FROM emp where deptno = DNUM;

BEGIN
OPEN c1;
LOOP
FETCH c1 BULK COLLECT INTO D_Rec.D_num, D_Rec.D_name LIMIT 2;
FORALL i IN 1 .. D_rec.D_num.COUNT
INSERT INTO dept2 (deptno , dname)
VALUES (D_Rec.D_num(i), D_Rec.D_name(i));

Open c2(D_Rec.D_num(i));
Loop
FETCH c2 BULK COLLECT INTO E_Rec.E_num, E_Rec.E_name LIMIT 5;
FORALL j IN 1 .. E_rec.E_num.COUNT
INSERT INTO emp2 (empno , ename, dname)
VALUES (E_Rec.E_num(j), E_Rec.E_name(j),D_Rec.D_name(i) );
EXIT WHEN C2%NotFound;
END LOOP;
Close c2;
EXIT WHEN C1%NotFound;
END LOOP;
CLOSE c1;
END;
Please help I want its solutuion!
Thanks in Advance
Khurram Naseem
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 11 2006
Added on Sep 13 2006
6 comments
1,315 views