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:
BEGIN INSERT INTO new_table SELECT * FROM old_table; END; /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
- Dozens more answers to tough Oracle questions from Brian Peasland are available.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
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.