Method for increasing the speed of millions of row data insert

zhaozj2021-02-16  71

There are two tables Table1, table2

Insert Table1 into Table2:

Now use two methods:

1, specify the rollback segment, the rollback segment is enough

Set Transaction Use Rollback Segment RBS1;

INSERT INTO TABLE1 NOLGGING

SELECT *.

COMMIT;

2, use the definition of Cursor, submit once every 5000 or 10,000 records

Declare

Cursor Cur_Select IS

SELECT T1, T2, T3 ..... from tabl1;

v_id number;

v_t Table1% rowtype;

Begin

Open cur_select;

loop

EXIT WHEN CUR_SELECT% NOTFOUND;

FETCH CUR_SELECT INTO V_T.T1, V_T.T2, V_T.T3 .....

INSERT INTO TABLE2

(T1, T2, T3 ...)

Values

(v_t.t1, v_t.t2, v_t.t3 .....);

V_ID: = V_ID 1;

IF v_id = 10000 Then

COMMIT;

v_id: = 0;

END IF;

End loop;

COMMIT;

END;

转载请注明原文地址:https://www.9cbs.com/read-18662.html

New Post(0)