Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9223699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:08:03+00:00 2026-06-18T04:08:03+00:00

In Oracle 11g when PL/SQL context finishing function/procedure automatically close opened cursors. Why in

  • 0

In Oracle 11g when PL/SQL context finishing function/procedure automatically close opened cursors. Why in many examples over the web users opening and closing their cursors?

Is this backward compatibility ?

What about REF-CURSORs ? Leaving procedure close them also ?

If cursor should be closed always what about handling exceptions? In EXCEPTION block do I have to check all cursors ISOPEN and then close them?

Basic script demonstrates auto-closing feature:

DECLARE
  PROCEDURE TEST IS
    CURSOR CUR_CLIENTS IS SELECT DUMMY CL_ID FROM DUAL;
    TYPE RT_CLIENTS IS TABLE OF CUR_CLIENTS%ROWTYPE;
    LT_CLIENTS RT_CLIENTS;
  BEGIN
    IF CUR_CLIENTS%ISOPEN THEN
      DBMS_OUTPUT.PUT_LINE('CLOSING CURSOR');
      CLOSE CUR_CLIENTS;
    END IF;
    OPEN CUR_CLIENTS;
    LOOP
      FETCH CUR_CLIENTS BULK COLLECT INTO LT_CLIENTS LIMIT 1000;
      EXIT WHEN LT_CLIENTS.COUNT = 0;
      FOR I IN 1..LT_CLIENTS.COUNT LOOP
        DBMS_OUTPUT.PUT_LINE(LT_CLIENTS(I).CL_ID);
      END LOOP;
    END LOOP;
  END TEST;
BEGIN
  DBMS_OUTPUT.PUT_LINE('--------------------');
  TEST;
  DBMS_OUTPUT.PUT_LINE('--------------------');
  TEST;
  DBMS_OUTPUT.PUT_LINE('--------------------');
  TEST;
  DBMS_OUTPUT.PUT_LINE('--------------------');
END;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:08:04+00:00Added an answer on June 18, 2026 at 4:08 am

    In your script, you are doing wrong because You are checking the cursor is opened or not, you are closing it if it is already opened, and again re-opened. If cursor is already opened then Do Not close it , just use it.

    In plsql,
    cursors opened within the inner block have obviously not been implicitly closed. Had they been closed, I would not have exceeded the maximum number of open cursors.


    In my experience:

    SQL> DECLARE    
      2     CURSOR last99 IS SELECT * FROM dual;    
      3  BEGIN
      4    DECLARE    
      5       CURSOR test01 IS SELECT * FROM dual;
      6       CURSOR test02 IS SELECT * FROM dual;    
      7       CURSOR test03 IS SELECT * FROM dual;    
    ............................    
    ............................    
     51       CURSOR test47 IS SELECT * FROM dual;    
     52       CURSOR test48 IS SELECT * FROM dual;    
     53    BEGIN    
     54       OPEN test01;    
     55       OPEN test02;    
     56       OPEN test03;   
    
     ..............    
    ...............   
    
     99       OPEN test46;    
    100       OPEN test47;  
    101       OPEN test48;    
    102    END;    
    104    --This last OPEN will cause an error     
    105    --from too many cursors.    
    106    OPEN last99;    
    107  END;    
    108  /    
    DECLARE    
    *    
    ERROR at line 1:    
    ORA-01000: maximum open cursors exceeded    
    ORA-06512: at line 2    
    ORA-06512: at line 106 
    

    You can close cursor in Exception block also.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The below procedure (in Oracle 11g release 1) accepts a sql as a parameter
I've installed Oracle 11g r2 to my machine and when I opened Oracle SQL
Context I have an Oracle 11g database instance and a SQL Server 2012 instance
I'm using oracle 11g sql developer I have a varchar2 column with dates as
Using .Net and Oracle 11g - I've been returning dataTables from a procedure inside
I'm writing some JDBC code which calls a Oracle 11g PL/SQL procdedure which has
I'm writing some JDBC code which calls a Oracle 11g PL/SQL procdedure which has
I am using oracle 11g express and sql developer. When I open SQL developer,
I'm using Oracle 11g Standard Edition. I would like to log all SQL queries,
I am using Oracle 11g and Oracle SQL Developer 3.2.20.09. I am creating a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.