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 loopas 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 loopis 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
- Dozens more answers to tough Oracle questions from Karen Morton 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.