Ask the Expert

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

    Requires Free Membership to View

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

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
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
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: