Problem solve Get help with specific problems with your technologies, process and projects.

Insert in a cursor takes hours to complete

We run an insert from Oracle SQL tool that selects 200,000 rows from various tables and inserts them in another...

table. This ends in 10 minutes. We try the same query inside a stored procedure in Oracle, and it runs for hours. Oracle version is 8.1.5 and runs on Windows NT.

Are you running the INSERT statement in the stored proc by using an explicit CURSOR? Are you looping through the cursor and performing a COMMIT every so often? These type of things can make your INSERT statement slow to a crawl.

Let's suppose that I have a simple INSERT statment, selecting data from a table, that I can run in SQL*Plus similar to the following:

INSERT INTO new_table SELECT * FROM old_table;
To run this statement in a PL/SQL block, just do the same:
   INSERT INTO new_table SELECT * FROM old_table;
Now this PL/SQL block can be put into a stored procedure for quick recall. There is no need to use a cursor for this. Oracle will create an implicit cursor for you.

For More Information

This was last published in August 2002

Dig Deeper on Oracle database design and architecture

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.