Close cursor after for loop?

Close cursor after for loop?

I read your answer regarding memory links. I know that when you explicitly open a cursor (OPEN c1; for example), you should close the cursor explicitly also (CLOSE c1). Do you also need to close the cursor after a for loop? For example:
 
FOR i in c1 LOOP
...
END LOOP;
Thanks.

    Requires Free Membership to View

    By submitting your registration information to SearchOracle.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchOracle.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

You can close the cursor at any time you are done with it. However, it is good programming practice to open the cursor right before the loop that processes it and then close the cursor when the loop finishes. The cursor is only used in the loop (after all, you're looping through the cursor's rowset) so if you do not close it right after the loop, you might forget to close it later.

This was first published in April 2006

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.