Q

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?

This Content Component encountered an error
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.
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

Dig deeper on Oracle database design and architecture

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

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.

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close