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!

'FETCH c BULK COLLECT INTO' for multiple columns.

484531Mar 15 2006 — edited Mar 15 2006
Hi all... I'm trying to write a bulk fetch for a cursor whihc selects a number of different columns from a table.
To best explain I'll paste some code here:

Cursor:
CURSOR cur1 IS
SELECT id, code, value
FROM   table1
WHERE  code in ('CODE1', 'CODE2', 'CODE3');
There are also about 7 other columns on this table which are not selected.

Within the BEGIN segment of the code I have the following:
OPEN cur1;
LOOP
  FETCH cur1 INTO l_id, l_code, l_value;
  EXIT WHEN cur1%NOTFOUND;
  v_sql_stmt := 'UPDATE table2 SET '||l_code||' = '||l_value||' WHERE  id = '||l_id||'';
  EXECUTE IMMEDIATE v_sql_stmt;
  v_count := (v_count + 1);
  IF v_count = 10000
  THEN
    COMMIT;
    v_count := 0;
  END IF;
END LOOP;
COMMIT;
CLOSE cur1;
I'm commiting every 10,000 rows due to rollback issues as there are around a total of 650,000,000 rows to be inserted when this script will run on our production database.

Now this is obviously taking a very long time and to try and speed things up a bit I would like to make this a BULK fetch of the cursor.
I've read a lot about how to do this but I can't seem to find a definitive syntax that will work for me.

Do I need to create three different tables to hold the fetched data? Do I need to use a LIMIT clause after the BULK COLLECT INTO for 10000 if I would like to commit here? Where does the EXIT WHEN clause go?

Thanks for any help on this... I'm so confused!

fakelvis
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 12 2006
Added on Mar 15 2006
1 comment
1,786 views