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!

What is the best way to batch update big table

Hawk333Mar 29 2016 — edited Mar 29 2016

I have this data of 100K+ that is imported on daily basis into a table. The data is coming from spool file and I need to parse it to identify every couple of rows (i.e., 10-20) as a separate batch. So the spool file will be split into thousands of separate files. There is a value I can find at the beginning of each batch, say it is 'x'. But now I'm thinking how to make the process as efficient as possible.

I though of FOR cursor as follows

...

v_seq NUMBER;

BEGIN

SELECT batch_seq.nextval into v_seq from dual;

FOR i IN (SELECT id, line FROM spool_tab)

LOOP

UPDATE spool_tab

SET line = v_seq

WHERE id = i.id;

IF  i.line = 'x' THEN

SELECT batch_seq.nextval into v_seq from dual;

END IF;

END LOOP

...

END;


But won't this way engine switch between PL/SQL and SQL for every single row, and hence slow down the performance?

Is there a better way to give a batch number for the entire set of rows when reach the value 'x'?


For reference, the spool_tab structure looks like this:

idlinebatch_no
1x
2y
3y
4x
5y
6y
7x


So I want to give first 3 rows batch_no 1, and rows 4-6 batch_no 3 and so own (but not always 3 rows, it depends on the x value presence).

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 26 2016
Added on Mar 29 2016
10 comments
1,141 views