Everybody knows that it takes a long time to insert a large number of records into a table. To improve the speed of insertion, you can use the PL/SWL loop FORALL.
In PL/SQL, use a cursor to fetch the rows from one table and insert them into the other table.
To reduce fetching time, do a BULK COLLECT INTO:
FETCHBULK COLLECT INTOLIMIT
To insert the fetched row, use the FORALL loop.
FORALL INDX IN .. SAVE EXCEPTIONS
You can also handle Exceptions by using the SAVE EXCEPTIONS option in the FORALL loop. Here, the FORALL loop acts as a bulk insert. When it encounters an exception, it just saves it and continues with the next record.
To view the exceptions that occurred during the insert, include the following statement after the FORALL loop:
EXCEPTIONWHEN bulk_errors THENFOR indx IN 1 .. SQL%BULK_EXCEPTIONS.COUNTLOOPerrno := SQL%BULK_EXCEPTIONS(indx).ERROR_INDEX;errmsg := SQLERRM(-1 * SQL%BULK_EXCEPTIONS(indx).ERROR_CODE);END LOOP;END;
Placing the keyword SAVE EXCEPTIONS in the FORALL loop stores all the encountered exceptions in BULK_EXCEPTIONS. Thus, the FORALL loop can be used for Bulk Insert and even Exceptions can be handled in that.
NOTE: The keyword SAVE EXCEPTIONS in the FORALL loop works only in Oracle9i.
Share the Post:
Share on facebook
Share on twitter
Share on linkedin
Overview
The Latest
4 Areas of Your Company Where Your Audio Really Matters
February 2, 2023
Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a
How to Turn on Chrome OS Developer Mode
February 1, 2023
Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS
Exploring the Latest Tech Trends Impacting the Real Estate Industry
January 31, 2023
The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may