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

Speedier way to open cursors?

I have got two cursor in master-detail. Usually I open all cursors with:

for cursor_1 loop
 for cursor_2 loop parameters 
 end loop 
end loop 
as Oracle taught me. Someone told me that in some conditions, this mode:
open cursor1
open cursor2
fetch cursor1
while cursor1
 fetch cursor 2
 while cursor2
 end loop 
end loop   
is speedier. Is it true?

Generally speaking, cursor processing methods don't have any inherent speed differences that I know of (if there are differences, they are minimal).

The key thing to note in your examples though is that you can't do what you want with the second format. Since it is a master detail relationship, you want to pass a parameter to the 2nd cursor in order to pull the children from the parent. If all you do is open the cursor, as you show, you don't get the proper parent/child relationship created and your code would return the wrong results.

Other than that code error, the answer as to speed is that I don't believe there is a "material" difference in which form of cursor looping you choose.

For More Information

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.

Please create a username to comment.