Skip to Main Content

Oracle Database Discussions

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!

FETCH, BULK COLLECT INTO, LIMIT

301618Mar 22 2004 — edited Mar 23 2004
I have 9247 records to insert to a temp table. I am tring to use FETCH, BULK COLLECT INTO, LIMIT. I set the LIMIT to 3000. The problem is it only fetches back 9000 records. The rest 247 can't be fetched. In the Oracle manual, it says with each iteration of the loop, the FETCH statement fetches 3000 rows (or less).
Here is my code. Thanks.

DECLARE

TYPE mTab1 IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
TYPE mTab2 IS TABLE OF tab.col1%TYPE INDEX BY BINARY_INTEGER;
TYPE mTab3 IS TABLE OF tab.col2%TYPE INDEX BY BINARY_INTEGER;

tab1 mTab1;
tab2 mTab2;
tab3 mTab3;

CURSOR c is SELECT
ROWID,
col1,
col2
FROM
tab
WHERE ... ORDER BY ROWID;
BEGIN
OPEN c;

LOOP
--bulk fetch into the three arrays with limited amount

FETCH c BULK COLLECT INTO
tab1, tab2, tab3
LIMIT 3000;

EXIT WHEN c%NOTFOUND;

BEGIN

FORALL n IN tab1.FIRST..tab1.LAST
INSERT INTO TMP_TAB values
(tab1(n),
tab2(n),
tab3(n));
COMMIT;

EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
DBMS_OUTPUT.PUT_LINE ('Stopped when inserting ... ' ||
sqlcode ||' ' || sqlerrm);
EXIT;
END;

END LOOP;

CLOSE c;
end;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 20 2004
Added on Mar 22 2004
2 comments
602 views