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!

Cursor Bulk Collect

SamFisherFeb 14 2012 — edited Feb 14 2012
Hello All,
I have a doubt regarding Cursor bulk collect. Both the versions are working fine.

1st Version: 
DECLARE
  CURSOR c1 IS (SELECT t2 FROM test10);
  TYPE typ_tbl IS TABLE OF c1%rowtype;
  v typ_tbl;
BEGIN
  OPEN c1;  
    FETCH c1 BULK COLLECT INTO v;
  CLOSE c1;
  FOR i IN v.first..v.last
  LOOP
    DBMS_OUTPUT.PUT_LINE(v(i).t2);
  END LOOP;  
END;

2nd version: 
DECLARE
  CURSOR c1 IS (SELECT t2 FROM test10);
  TYPE typ_tbl IS TABLE OF c1%rowtype;
  v typ_tbl;
BEGIN
  OPEN c1;
  LOOP                                                 --Loop added
    FETCH c1 BULK COLLECT INTO v;
    EXIT WHEN c1%NOTFOUND; 
  END LOOP;
  CLOSE c1;
  FOR i IN v.first..v.last
  LOOP
    DBMS_OUTPUT.PUT_LINE(v(i).t2);
  END LOOP;  
END;
Is it necessary to have a loop and exit when cursor notfound statementwhen used with Bulk Collect?

Edited by: SamFisher on Feb 14, 2012 1:26 PM
This post has been answered by Tubby on Feb 14 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 13 2012
Added on Feb 14 2012
12 comments
2,229 views