Site icon IT Tutorial

Bulk Insert and Bulk Update in Oracle Database

I will explain Bulk Insert and Bulk Update in Oracle Database in this article.

 

Bulk Insert and Bulk Update in Oracle

You can read the following article if you want to learn more details about Performance Tuning tips and Tricks.

SQL Tuning Tips and Tricks Tutorial in Oracle -2

 

 

 

 

Bulk Insert in Oracle

You should use Bulk Insert,Delete and Update instead of Single Insert,Delete and Update if you are executing Bulk operation.

Bulk insert,Delete and Update will give your system a huge performance boost.

 

 

If you insert high volume data serial,  you should switch this insert operation to the Bulk Insert.

For example; you can insert all MSD.TEST_TABLE records to the MSD.TEST_TABLE_NEW serial as follows.

insert into MSD.TEST_TABLE_NEW select * from MSD.TEST_TABLE;
commit;

 

But if MSD.TEST_TABLE count is very big, then you should use Cursor and Forall to perform Bulk Insert as follows.

 

DECLARE
CURSOR c_liste
IS
select * from MSD.TEST_TABLE;

TYPE TListe IS TABLE OF MSD.TEST_TABLE%ROWTYPE;

r_liste TListe;
l_hata VARCHAR2 (20000);
BEGIN
OPEN c_liste;

LOOP
FETCH c_liste
BULK COLLECT INTO r_liste
LIMIT 1000;

EXIT WHEN r_liste.COUNT () = 0;

BEGIN
FORALL i IN 1 .. r_liste.LAST
insert into MSD.TEST_TABLE_NEW
VALUES r_liste (i);
END;

COMMIT;
END LOOP;

COMMIT;

CLOSE c_liste;
END;
/

 

This Bulk Insert operation speed up to 30 times faster according to Serial Insert.

 

 

Bulk Update in Oracle

 

Likewise you can perform bulk update as follows.

SET TIMING ON

DECLARE
CURSOR c_liste
IS
SELECT /*+ PARALLEL(TT, 8) */ * FROM MSD.TEST_TABLE TT
WHERE TT.SUBSCRIPTION_ID IS NOT NULL;

TYPE TListe
IS TABLE OF MSD.TEST_TABLE%ROWTYPE;

r_liste TListe;
l_hata VARCHAR2 (2000);
BEGIN
OPEN c_liste;

LOOP
FETCH c_liste
BULK COLLECT INTO r_liste
LIMIT 1000;

EXIT WHEN r_liste.COUNT () = 0;

BEGIN
FORALL i IN 1 .. r_liste.LAST
UPDATE PR_OSB_CUSTOM.SEQUENCING_RUNTIME_MAIN SEQ
SET SEQ.MESSAGE = updateXML(SEQ.MESSAGE, '//*:businessID/text()', 'MSD-'||r_liste (i).SUBSCRIPTION_ID|| '_' || r_liste (i).SYSTEM_NAME),
SEQ.BUSINESS_ID = 'MSD-'||r_liste (i).SUBSCRIPTION_ID|| '_' || r_liste (i).SYSTEM_NAME
WHERE SEQ.ID = r_liste (i).ID
AND seq.BUSINESS_ID NOT LIKE 'MSD%';

END;

COMMIT;
END LOOP;

COMMIT;

CLOSE c_liste;
END;
/

 

If you are processing ( DML ) high volume data, you should use Bulk Insert or Bulk Update or Bulk Delete instead of Serial Insert, update and delete.

 

 

 

 Do you want to learn Top 30 SQL Tuning Tips and Tricks, then Click this link adn read the articles.

SQL Tuning Tips and Tricks Tutorial in Oracle -2

 

Exit mobile version