ORA-01000 Max Cursors even when closing

When I execute the following code, the number of open cursors increases by 2, even though I am disposing of the reader, command and connection.
long returnValue=0;               
OracleConnection myOracleConnection = null;
OracleCommand cmd = null;
OracleDataReader reader = null;
try
     myOracleConnection = new OracleConnection(strDBConn);
     myOracleConnection.Open();
     cmd = new OracleCommand(spGetNextSequenceNo, myOracleConnection) ;
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.Add(prmSystemType,intSystemType);
     cmd.Parameters.Add(prmSection,strSection);
     cmd.Parameters.Add(new OracleParameter("rc1", OracleType.Cursor)).Direction = ParameterDirection.Output;
     reader = cmd.ExecuteReader();
     if(reader.Read())
          int colCount = reader.GetOrdinal("NextSequence");
          returnValue = reader.GetInt64(colCount);
     return returnValue;
catch(Exception myException)
     return 0;
finally
     if( myOracleConnection != null )
          myOracleConnection.Close();
          myOracleConnection = null;
     if( cmd != null )
          cmd.Dispose();
          cmd = null;
     if( reader != null )
          reader.Close();
          reader.Dispose();
          reader = null;
the stored procedure being called is given below
CREATE OR REPLACE PROCEDURE SPCRISPGETTRANSFORMFIELDS(
     RC1     IN OUT crisp.globalPkg.RCT1) AS
/* Force:DPP      Version: 1.0.5      DateModified: 2003:07:25 */
     CURSOR curExtractsTrnsfrmLook IS
          SELECT
               name
          FROM
               CRISP_SYS_EXTRCTS_TRNSFRM_LOOK;
     myRowVariable     curExtractsTrnsfrmLook%ROWTYPE;
BEGIN
     OPEN RC1 FOR
          SELECT
          FROM
               CRISP_SYS_EXTRCTS_TRNSFRM_LOOK;
     OPEN curExtractsTrnsfrmLook;
     FETCH curExtractsTrnsfrmLook INTO myRowVariable;
     IF curExtractsTrnsfrmLook%NOTFOUND THEN
          raise_application_error(-20999, 'ERROR encountered when retrieving rows from CRISP_SYS_EXTRCTS_TRNSFRM_LOOK (spCRISPGetTransformFields)');     
     END IF;
     CLOSE curExtractsTrnsfrmLook;
EXCEPTION
     WHEN OTHERS THEN
          IF curExtractsTrnsfrmLook%ISOPEN THEN
               CLOSE curExtractsTrnsfrmLook;
          END IF;
          RAISE;
END SPCRISPGETTRANSFORMFIELDS;
I am closing the cursor checking for the existence of any rows, but even this cursor appears in the v$open_cursor view.
Can anyone explain why this is?

I am having the exact same problem and am also closing and disposing the datareader and the connection. have you heard anything?

Similar Messages

  • ORA-01000 max cursors exceeded

    After what I thought was fixing the problem, we are yet again hitting ORA-01000.
    We have an application which was left running over Christmas and New Year but with no one using it.
    We came back and the first time someone tried to do something we hit the ORA-01000 error.
    Has anyone seen anything like this before?
    I'm not ruling out a problem in our code somewhere but it seems odd that when the application is actually being used we have no problems but if we leave it to sit for a while it suddenly runs out of cursors!
    Cheers
    Alex

    what is the application doing? Is any other application accessing the database? Are you using statement caching?

  • Firefox constantly runs in the background even when closed

    Hi
    I have Firefox 3.6.8 running on Windows Vista.
    I have found that Firefox constantly runs in the background even when i have just booted up the computer or when i have closed it.
    Firefox seems to constantly run with 5000-20000 K bytes in the memory.
    When i have Firefox running to look at webpages, there are two processes running. When i close Firefox there is one process running. If i end the process using the task manager, it only takes seconds before it starts to run again.
    I know this isnt normal because i keep a good eye on the processes running on my computer. So unless the latest version of Firefox requires this process running all the time, it looks like i have a probably.
    Ive scanned my computer with zonealarm, avast, superantispyware and spybot to scan my computer for viruses. One of the pieces of software found a virus and it deleted it successfully.
    Im not too sure if this is a virus that is hiding in my system or whether its part of the latest version of Firefox.
    Firefox isnt showing the usual signs of a virus. As in it doesnt try to redirect me to random websites and it doesnt try to get me to download something.
    I hope someone can help me please.
    Rob

    After talking to someone very helpful on the live chat support.
    It appears like i have a virus that is very good at hiding from detection from anti-virus/spyware software.
    No idea what intentions the virus has as its not showing any sort of virus like behaviour.
    I called the old installation a different name and closed the Firefox process. A few seconds later, instead of a Firefox process starting again a different executable started.

  • Connecting HP Notebooks to External Devices even when closed

    Dear HP Community,
    Even if you are a notebook user, once in a while, when working in the office, you would love to hook-up your notebook computer to a bigger LCD Monitor, plug-in  either a regular full-size USB keyboard and mouse, or  a wireless keyboard and mouse.
    I am doing it now, but the akward part is that my notebook has to be open and turned-on to be able to do this, is there any development in HP that would let the user hook up his/her HP notebook to an LCD monitor and keyboard and mouse, and with a push of a botton on the notebook  (even when the lcd-lid is closed) can turn the notebook into a "small footprint" desktop unit...
    This question was solved.
    View Solution.

    Dont know about at the push of a button, however you could configure (in power saving options under control panel) your machine so if the lid is shut, it only turns the laptop monitor off, as opposed to sleep mode/hibernate.
    Would be the way id tackle it anyway mate.

  • Tcp listen accepts multiple simultaneo​us connection​s even when closed

    LV 6.0.2, win 2k
    I am trying to set up a server that will recieve data from multiple clients. If I set up a TCP listen vi on the server, then I have found that any (or the same) client can open multiple connections on this port and send data to it even though the server has only called the TCP listen VI once and only has a reference for the first connection. The subsequent connections seem to be accumlating in the port buffer and the data can in fact be retrieved with subsequent calls to TCP listen on that port regardless of whether the client has closed the connection long ago and forgotten about the transaction.
    This could perhaps be considered either a feature or a bug. For me it is undesirabl
    e. I would prefer that attempted connections to the server were rejected if the server is not actually actively listening on the port. Otherwise clients can easily flood the port.
    Is there some way to control this behaviour, or perhaps a completely different approach? or is there some way to control the port settings such as buffer size or max number of connections allowed, and a way to clear the buffer without processing all the connections?
    Thanks in advance for any thoughts.

    Thanks for the comments.
    I don't seem to get the same behaviour you describe.
    When you say 'if the server closes the connection after reading the first request, then it will not process the rest of the requests waiting in the queue'. I find that after the server closes the connection (with TCP close connection) then there can still be a huge backlog of connections to the same port (requests) which are still waiting to be processed. Another call to TCP listen retrieves one of the old ones, it doesn't wait around for a legitimately new request from a client.
    Where you say 'When you leave the connection open on the server side, you can receive multiple commands this way, but it also blocks other clients from connecting until the curre
    nt client disconnects'. This is in fact my main difficulty. Even with a connection held open other clients (or the same client) CAN make other connections and send data through that connection. This then backs up if the server is not processing them faster than recieving them.
    I've attached vi's which should demonstrate the issue.
    I couldn't check your vi's. I'm missing the EOC error.vi and one other I think. Ultimately I hope to do something similar with multiple open connections, but still need the server to be able to refuse connections if it wants to. Something I don't seem to be able to do. The connections just keep coming regardless of how the server is set up.
    Thanks again.
    Steve
    Attachments:
    server.vi ‏229 KB
    client.vi ‏28 KB

  • Firefox start taking more memory without stop, even when closed

    Hi Firefox Team,
    I have been Firefox user for almost 10 years. I love your product. But recently Firefox has show an estrange behavior. After use my laptop (VAIO, Intel i7, 12GB RAM, 256 SSD, Windows 7 Professional x64) without restart it for a couple of days (instead of restart, I sleep it), and with Firefox (35.0.1) running the same period of time, it start to take memory without stop, 5MB/s approximately. A couple of time I did some test and it reach 2 GB of RAM and continue. Also, even if I close Firefox, it still running on background taking the memory, so I have to end it from Task Manager.
    Please let me know which evidence or test should I perform so I can send you more information, beside description.
    Regards,
    Ricardo

    Check out this [https://support.mozilla.org/en-US/kb/firefox-uses-too-much-memory-ram site] see if it helps.
    Have a great day!!
    Jon

  • Max cursors exceeds problem(ORA-01000)

    Hi
    In my server open_cursors is set as 300 .We are developing a java application(using struts & Jboss web server) nearly 10 computers access the oracle 10g server through plsql procedures/functions ,frequently I am getting ORA-01000 -MAX CURSOR EXCEEDS errors,what should I do .please.....
    by
    s_bala

    That means there is two cursor related parameters
                                            |
                                            |
                                            |
                                            |
                        |                                        |     
    1)Cached cursors                              2)Currently open cursor
    1)Cached cursors     2)Currently open cursor
    SQL> select o.sid,osuser,machine,count(*) num_curs
    from v$open_cursor o,v$session s
    WHERE user_name = 'ERP' and
    o.sid = s.sid GROUP BY o.sid,osuser,machine
    ORDER BY num_curs DESC;     SQL>select max(a.value) as highest_open_cur,
         p.value as max_open_cur
         from v$sesstat a, v$statname b, v$parameter p
         where a.statistic# = b.statistic#
         and b.name = 'opened cursors current'
         and p.name= 'open_cursors'group by p.value;
    THIS IS THE RESULT I GOT
    SID OSUSER MACHINE NUM_CURS
    106 x 18
    93 x 14
    124 x 14
    152 x 13
    90 y y 11
    121 z 8
    132 a 8
    118 b b 6
    105 c 5
    131 b 5
    98 d d 4
    95 x 3
    147 y y 3
    89 e 2
    119 e 2     THIS IS THE RESULT I GOT
    HIGHEST_OPEN_CUR MAX_OPEN_CUR
    83 500
         -This is related to ORA-01000 -MAX CURSOR EXCEEDS
    From the above what I understood is correct ???
    F) How to clear 1)Cached cursors ? (or) how to reduce NUM_CURS (from the above left side table ).
    G) will the 1)Cached cursors give any problems to our database.

  • ORA-01000 maximum open cursors exceeded - help!

    Hi, I need some help with resolving ORA-01000 maximum cursors exceeded issue.I know this issue has been discussed before. I know this is caused because of not closing the resultset and statement, connection objects at the right place.
    Can anyone guide me where I should close them?. should they be closed inside the while(rs.next()) loop? There are two prepared statments. I am sure closing in finally block is not enough.
    It would help if you show me by typing the code for closing rs , ps, rs2, ps2, and conn .. should conn be closed too? if yes where..
    Connection conn = null;
    PreparedStatement ps = null;
    PreparedStatement ps2 = null;
    ResultSet rs = null;
    ResultSet rs2 = null;
    ArrayList arrayList = new ArrayList();
    displayerDO pdo = null;
    DocTypeDO dtdo = null;
    StringBuffer sql = new StringBuffer();
    sql.append("SELECT displayer_id, name FROM tech_displayers ORDER BY name");
    StringBuffer sql2 = new StringBuffer();
    sql2.append(" SELECT D.doc_type_id, D.name" +
    " FROM tech_DOC_TYPES D, tech_DOC_TYPE_displayERS P" +
    " WHERE D.default_displayer_id = P.displayer_id" +
    " AND P.displayer_id = ?");
    if(VERBOSE)
    Debug.displayln("displayingControllerDAOORCL.getdisplayers(): sql = " + sql.toString());
    Debug.displayln("displayingControllerDAOORCL.getdisplayers(): sql2 = " + sql2.toString());
    try
    conn = DbUtil.getConnection("tech");
    ps = conn.prepareStatement(sql.toString());
    ps2 = conn.prepareStatement(sql2.toString());
    rs = ps.executeQuery();
    while(rs.next())
    pdo = new displayerDO();
    pdo.setdisplayerId(rs.getInt("displayer_id"));
    pdo.setName(rs.getString("name"));
    ps2.setInt(1, rs.getInt("displayer_id"));
    rs2 = ps2.executeQuery();
    while(rs2.next())
    dtdo = new DocTypeDO();
    dtdo.setDocTypeId(rs2.getInt("doc_type_id"));
    dtdo.setName(rs2.getString("name"));
    // get displayer name from FIRST result set
    dtdo.setdisplayer(rs.getString("name"));
    pdo.addDocType(dtdo);
    arrayList.add(pdo);
    catch(SQLException sqle)
    if(VERBOSE)
    Debug.displayln("displayingControllerDAOORCL.getDocdisplayers(): exception e=" + sqle);
    throw sqle;
    finally
    DbUtil.close(rs2);
    DbUtil.close(ps2);
    DbUtil.close(ps, rs, conn);
    Thanks,
    scott

    Scott,
    From the code it looks like for every row of "ps" you are executing "ps2".
    You should close ps2 as soon as it is done.
    ie.,
    <pre>
    while(rs.next())
    pdo = ...
    rs2 = ps2.executeQuery()
    while (rs2.next())
    }// end of while(rs2.next())
    rs2.close(); // NEW LINE: Close the resultset here.
    }// end of while(rs.next())
    HTH
    Ashok

  • Cursors are not closed when using Ref Cursor Query in a report  ORA-01000

    Dear Experts
    Oracel database 11g,
    developer suite 10.1.2.0.2,
    application server 10.1.2.0.2,
    Windows xp platform
    For a long time, I'm hitting ORA-01000
    I have a 2 group report (master and detail) using Ref Cusor query, when this report is run, I found that it opens several cursors (should be only one cursor) for the detail query although it should not, I found that the number of these cursors is equal to the number of master records.
    Moreover, after the report is finished, these cursors are not closed, and they are increasing cumulatively each time I run the report, and finally the maximum number of open cursors is exceeded, and thus I get ORA-01000.
    I increased the open cursors parameter for the database to an unbeleivable value 30000, but of course it will be exceeded during the session because the cursors are increasing cumulatively.
    I Found that this problem is solved when using only one master Ref Cursor Query and create a breake group, the problem is solved also if we use SQL Query instead of Ref Query for the master and detail queries, but for some considerations, I should not use neither breake group nor SQL Query, I have to use REF Cursor queries.
    Is this an oracle bug , and how can I overcome ?
    Thanks
    Edited by: Mostafa Abolaynain on May 6, 2012 9:58 AM

    Thank you Inol for your answer, However
    Ref Cursor give me felxibility to control the query, for example see the following query :
    function QR_1RefCurDS return DEF_CURSORS.JOURHEAD_REFCUR is
    temp_JOURHEAD DEF_CURSORS.JOURHEAD_refcur;
              v_from_date DATE;
              v_to_date DATE;
              V_SERIAL_TYPE number;
    begin
    SELECT SERIAL_TYPE INTO V_SERIAL_TYPE
    FROM ACC_VOUCHER_TYPES
    where voucher_type='J'
    and IDENT_NO=:IDENT
    AND COMP_NO=TO_NUMBER(:COMPANY_NO);
         IF :no_date=1 then
                   IF V_SERIAL_TYPE =1 THEN     
                   open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
                   FROM JOURHEAD
                   WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
                   AND IDENT=:IDENT
              AND ((TO_NUMBER(VOCH_NO)=:FROM_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NULL)
              OR (TO_NUMBER(VOCH_NO) BETWEEN :FROM_NO AND :TO_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NOT NULL )
              OR (TO_NUMBER(VOCH_NO)<=:TO_NO and :FROM_NO IS NULL AND :TO_NO IS NOT NULL )
              OR (:FROM_NO IS NULL AND :TO_NO IS NULL ))
                   ORDER BY TO_NUMBER(VOCH_NO);
                   ELSE
                   open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
                   FROM JOURHEAD
                   WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
                   AND IDENT=:IDENT               
              AND ((VOCH_NO=:FROM_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NULL)
              OR (VOCH_NO BETWEEN :FROM_NO AND :TO_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NOT NULL )
              OR (VOCH_NO<=:TO_NO and :FROM_NO IS NULL AND :TO_NO IS NOT NULL )
              OR (:FROM_NO IS NULL AND :TO_NO IS NULL ))     
                   ORDER BY VOCH_NO;          
                   END IF;
         ELSE
                   v_from_date:=to_DATE(:from_date);
                   v_to_date:=to_DATE(:to_date);                         
              IF V_SERIAL_TYPE =1 THEN
                   open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
                   FROM JOURHEAD
                   WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
              AND IDENT=:IDENT                         
                   AND ((voch_date between v_from_date and v_to_date and :from_date is not null and :to_date is not null)
                   OR (voch_date <= v_to_date and :from_date is null and :to_date is not null)
                   OR (voch_date = v_from_date and :from_date is not null and :to_date is null)
                   OR (:from_date is null and :to_date is null ))     
                   ORDER BY VOCH_DATE,TO_NUMBER(VOCH_NO);     
              ELSE
                   open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
                   FROM JOURHEAD
                   WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
                   AND IDENT=:IDENT                         
              AND ((voch_date between v_from_date and v_to_date and :from_date is not null and :to_date is not null)
                   OR (voch_date <= v_to_date and :from_date is null and :to_date is not null)
                   OR (voch_date = v_from_date and :from_date is not null and :to_date is null)
                   OR (:from_date is null and :to_date is null ))     
                   ORDER BY VOCH_DATE,VOCH_NO;          
              END IF;
         END IF;               
         return temp_JOURHEAD;
    end;

  • Having issues with my MacBook. Even when the internet is disconnected, apps are still closing and opening on their own. I sometimes do not have control over my cursor.....any suggestions?

    Having issues with my MacBook. Even when the internet is disconnected, apps are still closing and opening on their own. I sometimes do not have control over my cursor.....any suggestions?

    There are several possible causes for this issue. Please take each of the following steps that you haven't already tried until it's resolved. Some may not be apply in your case.
    1. Follow the instructions in this support article, and also this one, if applicable. A damaged or defective AC adapter could be the cause, even if it's the right kind.
    2. Open the Bluetooth preference pane in System Preferences and delete all pointing devices other than the trackpad, if applicable. Disconnect any USB pointing devices. By a "pointing device," I mean a peripheral that moves the cursor, such as a trackpad, mouse, trackball, or graphics tablet. A plain keyboard is not a pointing device.
    3. Start up in safe mode and test, preferably without launching any third-party applications. If you don't have the problem in safe mode, but it comes back when you restart as usual, stop here and post your results. Do the same if you can't start in safe mode. If there was no difference in safe mode, go on to the next step.
    4. Reset the System Management Controller.
    5. If you're using a Bluetooth trackpad, investigate potential sources of interference, including USB 3 devices.
    6. A swollen battery in a portable computer can impinge on the trackpad from below and cause erratic behavior. If you have trouble clicking the trackpad, this is likely the reason. The battery must be replaced without delay.
    7. Press down all four corners of the trackpad at once and release. If there's any effect, it's likely to be temporary, and the unit needs to be serviced or replaced.
    8. There's a report that a (possibly defective) Thunderbolt Ethernet adapter can cause the built-in trackpad of a MacBook to  behave erratically. If you're using such an adapter, disconnect it and test.
    9. There's also a report of erratic cursor movements caused by an external display that was connected but not turned on.
    10. If none of the above applies, or if you have another reason to think that your computer is being remotely controlled, remove it from the network by turning off Wi-Fi (or your Wi-Fi access point), disconnecting from a Bluetooth network link, and unplugging the Ethernet cable or USB modem, whichever is applicable. If the cursor movements stop at once, you should suspect an intrusion.
    11. Make a "Genius" appointment at an Apple Store to have the machine and/or external trackpad tested.

  • Implicit PL/SQL cursors remain open, causing ORA-01000 (Client 9.2.0.1)

    Hello,
    since migrating our system from Oracle Client 9.0.X to 9.2.0.1 (Windows XP), i am encountering troubles when calling a stored procedure from a Cobol-Program:
    after a while i run into a 'Maximum open cursors exceeded'-message (ORA-01000)
    The stored procedure returns a cursor (ref_cursor)
    When Executing the stored procedure, there are actually 2 cursors involved, in fact the stored PL/SQL procedure implicitely opens a child-cursor when doing a select within the PL/SQL.
    After fetching the result and closing the cursor in my cobol-program, it correctly closes the cursor associated with the stored-procedure, but it does not close the cursor that was implicitely opened by oracle.
    After a while i am running into a Maximum open cursors message, because those cursors have not properly been closed.
    Here's a simple PL/SQL package that illustrates the problem:
    create or replace package scott.SCOTTS_PACKAGE is
    type ref_cursor IS REF CURSOR;
    function GET_EMP(EMP_IN CHAR) return ref_cursor;
    end SCOTTS_PACKAGE;
    create or replace package body scott.SCOTTS_PACKAGE is
    -- Function and procedure implementations
    function GET_EMP(EMP_IN CHAR) return ref_cursor is
    MyCurs ref_cursor;
    begin
    OPEN MyCurs FOR
    SELECT EMPNO ,
    ENAME ,
    JOB
    FROM SCOTT.EMP
    WHERE ENAME = EMP_IN;
    return(MyCurs);
    end;
    end SCOTTS_PACKAGE;
    Here are some exerpts from my cobol program:
    (The program iterates 100x through the section that executes the PL/SQL. After each iteration an additional open cursor remains in the database)
    003800 EXEC SQL BEGIN DECLARE SECTION END-EXEC.
    003900*
    004000 01 SQL-USERNAME PIC X(16) VARYING.
    004100 01 SQL-PASSWD PIC X(16) VARYING.
    004200 01 SQL-DBNAME PIC X(64) VARYING.
    004300 01 ORACLE.
    004700 02 ORA-CUR-EMP SQL-CURSOR.
    01 EMPREC.
    02 EMPREC-EMPNO PIC X(4).
    02 EMPREC-ENAME PIC X(10).
    02 EMPREC-JOB PIC X(9).
    005400 EXEC SQL END DECLARE SECTION END-EXEC.
    018400 PROCEDURE DIVISION.
    CONTINUE.
    018700 EXEC SQL
    018800 WHENEVER SQLERROR DO PERFORM SQL-ERROR
    018900 END-EXEC.
    019000*
    CONTINUE.
    019100 EXEC SQL
    019200 WHENEVER NOT FOUND DO PERFORM SQL-NOT-FOUND
    019300 END-EXEC.
    022400 EXEC SQL
    022500 ALLOCATE :ORA-CUR-EMP
    022600 END-EXEC
    PERFORM VARYING I FROM 1 BY 1 UNTIL I > 100
    ACCEPT DUMMY FROM TER
    IF DUMMY = "E"
    MOVE 100 TO I
    END-IF
    PERFORM GET-EMP
    ADD 1 TO I
    END-PERFORM
    119300 GET-EMP SECTION.
    119400************************
    119500 GAM0.
    MOVE SPACES TO EMPREC-EMPNO EMPREC-JOB
    MOVE "SMITH" TO EMPREC-ENAME
    120200 EXEC SQL AT SSSI EXECUTE
    120300 BEGIN
    120400 :ORA-CUR-EMP:=
    120500 SCOTT.SCOTTS_PACKAGE.GET_EMP(:EMPREC-ENAME );
    120900
    END;
    121000 END-EXEC
    121200 IF DB-ERR-CODE NOT = HIGH-VALUE
    121300 DISPLAY "CCSIFSO:GET-AUTRE-MATR:APPEL PERS... OK"
    121400 EXEC SQL
    121500 FETCH :ORA-CUR-EMP
    121600 INTO
    121700 :EMPREC-EMPNO,
    121800 :EMPREC-ENAME,
    121900 :EMPREC-JOB
    122400 END-EXEC
    122500 END-IF
    122600*
    122700 IF DB-ERR-CODE NOT = HIGH-VALUE
    122800 DISPLAY "CCSIFSO:GET-AUTRE-MATR:APPEL FETCH.. OK"
    123000 ELSE
    123100 MOVE LOW-VALUE TO DB-ERR-CODE
    123200 END-IF
    123300 EXEC SQL
    123400 CLOSE :ORA-CUR-EMP
    123500 END-EXEC
    123600 GA-EX.
    123700 EXIT.
    124000 SQL-NOT-FOUND SECTION.
    124100*----------------------
    124200 NF0.
    124300 DISPLAY "CCSIFSO:SQL-NOT-FOUND SECTION."
    124400 MOVE HIGH-VALUE TO DB-ERR-CODE.
    124500 NF-EX.
    124600 EXIT.
    124700*
    124800 SQL-ERROR SECTION.
    124900*-----------------
    125000 ER0.
    125200 EXEC SQL
    125300 WHENEVER SQLERROR CONTINUE
    125400 END-EXEC
    125700 MOVE HIGH-VALUE TO DB-ERR-CODE
    125800*
    126100 DISPLAY "ORACLE ERROR DETECTED: " SQLCODE UPON TER
    126200 DISPLAY SQLERRMC UPON TER
    126300*
    126400 EXEC SQL AT SSSI
    126500 ROLLBACK WORK
    126600 RELEASE
    126700 END-EXEC
    126800 DISPLAY "----------------------------" UPON TER
    126900 DISPLAY " ! ROLLBACK ET DISCONNECT ! " UPON TER
    127000 DISPLAY "----------------------------" UPON TER
    127200 CALL "PPTERMJ".
    127400 ER-EX.
    127500 EXIT.
    Finally here's an exerpt from V$OPEN_CURSOR, after a few iterations:
    1 begin :b1 := SCOTT . SCOTTS_PACKAGE . GET_EMP (:b2 ) ; END ;
    2 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    3 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    4 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    5 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    6 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    7 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    8 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    9 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    10 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    11 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    As you see, there is only 1 cursor starting with 'begin ... '
    but there are 10 implicit cursors 'SELECT EMPNO, ... ' that have not been properly closed, nor reused by ORACLE.
    In our old configuration (ORACLE CLient 9.0.X), you would only see:
    1 begin :b1 := SCOTT . SCOTTS_PACKAGE . GET_EMP (:b2 ) ; END ;
    2 SELECT EMPNO , ENAME , JOB FROM EMP WHERE ENAME = :B1
    meaning all the other cursors have properly been closed.
    As a conclusion: the program correctly closes the implicit cursors when using a 9.0 Client, wheras the implicit cursors remain open on Client 9.2.0.1 (Windows XP)
    The underlying database can be either 8.i or 9, the problem remains the same.
    Finally here's a small Delphi code, using ODAC-components, that somewhat illustrates the same problem:
    procedure TForm1.ExecProcClick(Sender: TObject);
    var I: INTEGER ;
    begin
    FOR I := 1 TO 5 DO
    BEGIN
    SP1.StoredProcName:='SCOTT.SCOTTS_PACKAGE.GET_EMP';
    SP1.Prepare;
    SP1.ParamByName('EMP_IN').AsString := 'SMITH';
    SP1.ExecProc;
    SP1.Next;
    SP1.Close;
    SP1.UnPrepare;
    END;
    end;
    After each call to 'PREPARE', an additional implicit cursor remains open on the database. (using Oracle Client 9.2.0.1)
    On our old system (Oracle Client 9.0 or 8.X), the same program would not generate accumulating open cursors on the database
    Any suggestions would be welcome,
    Claude

    Cobol.. been many years since I last even saw some Cobol source code. Invokes all kinds of memories. :-)
    Since you found the patch, the advice is superfluous, but works. Close the cursor at the PL/SQL side, e.g.
    create or replace procedure CloseRefCursor( cRefCursor TYPELIB.TRefCursor ) is
    begin
      close cRefCursor;
    exception when OTHERS then
      -- if the cursor is already gone, not a problem
      NULL;
    end;In Delphi for example, one can subclass the class used for ref cursor calls and add a call to the above PL/SQL proc in the destructor. Or add create a standard Cobol close ref cursor section that does similar.

  • Cannot figure out why "ORA-01000 Maximum open cursors" is shown...

    Hello there ...
    I am programming a PL/SQL Code that is throwing 0RA-01000 Maximum Open Cursors Exceeded.
    Having already read quite a lot about ORA-01000 errors, I know I should be closing cursors, and have already tried setting OPEN_CURSORS parameter to a high number (1000).
    I declared a lot of procedures in my pl/sql, each of which uses one cursor since i am working with a non-Oracle table linked by ODBC ... and each procedure sometimes does thousands of inserts -- but all WITHIN the explicit cursors. The explicit cursors are not declared within each loop.
    I already checked the code many times, and made sure all open cursors are closed. In addition, I also verified the numberopen cursors generated by the PL/SQL by running the following SQL after every procedure i run... and outputting it... and it appears the value just keeps on increasing, even though I had explicitly closed all the cursors in all the earlier procedures.
    What is funny is that the most number of cursors reported by the code below only hits 150+ cursors. Nowhere near the 1000 open_cursors limit per session.
    select a.value into strtxt --, b.name        
            from v$mystat a, v$statname b
            where a.statistic# = b.statistic#
            and a.statistic#= 3;When I run the procedures separately though, all the procedures run smoothly (even when I had not yet updated the open_cursors parameter).
    I was thinking of the following, but maybe you have some other ideas?
    Does this have anything to do with my procedures not being stored procedures?
    Or should i be committing records within my procedures instead of out of it?
    I really have run into a wall and would really appreciate any tips or helps on this. Thanks in advance!
    My basic pl/sql code looks like below. I did not give the actual details cause it will be too long (up to 5000 lines).
    DECLARE
    PROCEDURE proc1
    IS
        CURSOR cur_hca
           is
               select ...from..where;
       TYPE cur_hca_fetch
            Is TABLE OF cur_hca%ROWTYPE
                INDEX BY PLS_INTEGER;
        temp_collect cur_hca_fetch;
    BEGIN
       open cur_hca;         --cur_hca is the cursor name.
                                      --i use exactly the same cursor name in the other procedures
          loop
             fetch cur_hca bulk collect into temp_collect LIMIT 1000;
             exit when temp_collect.count=0
             for indx in 1 .. temp_collect.count
                loop
                  ...run some sql
                end loop;
          end loop;
      close cur_hca;
    END proc1;
    PROCEDURE proc2   --almost the same as above the only changes are the query for the
                                 -- cursor and the sql that happens for each record
    IS
    BEGIN
       open cur_hca;         --cur_hca is my cursor name
          loop
          end loop;
      close cur_hca;
    END proc2;
    ... up to 40 other very similar procedures
    BEGIN
       proc1;
       commit;
       select a.value into strtxt
            from v$mystat a, v$statname b
            where a.statistic# = b.statistic#
            and a.statistic#= 3;
      DBMS_OUTPUT.PUT_LINE('Number of Cursors After STATUSproc1: ' || strtxt); 
       proc2;
       commit;
       select a.value into strtxt
            from v$mystat a, v$statname b
            where a.statistic# = b.statistic#
            and a.statistic#= 3;
       DBMS_OUTPUT.PUT_LINE('Number of Cursors After STATUSproc2: ' || strtxt); 
       ... 40 other procedures
    END;Edited by: user4872285 on May 6, 2013 6:49 PM
    Edited by: user4872285 on May 6, 2013 7:01 PM
    Edited by: user4872285 on May 6, 2013 8:02 PM
    Edited by: user4872285 on May 6, 2013 8:03 PM

    PL/SQL code usually leaks reference cursors and DBMS_SQL cursors - as the ref cursor/DBMS_SQL interface used has a global (session static) scope.
    PL/SQL has an intelligent garbage collector that will close local implicit and explicit cursors, when the cursor variable goes out of scope.
    If you define an explicit cursor globally (package interface), then it can only be opened once. The 2nd attempt results in a ORA-06511: PL/SQL: cursor already open exception. So code cannot leak explicit cursors as code cannot reopen an existing opened explicit cursor.
    I have never seen Oracle leaking cursors internally. So I would be hesitant to call what you are seeing, a bug. If your code is using explicit cursors (even static/global ones), your code cannot leak these cursors, even if your code does not close them. Worse case - the cursor remains open, however new copies cannot be created while it is open.
    So I think your are looking at the wrong thing - explicit cursors. These are not the cursors that are leaking in my view (simply because code cannot reuse and open an already opened explicit cursor). Here is an example:
    SQL> show parameter cursors
    NAME                                 TYPE        VALUE
    open_cursors                         integer     300
    session_cached_cursors               integer     50
    // procedure that seems to "leak" an explicit cursor handle
    // as it does not explicitly closes the handle
    SQL> create or replace procedure CursorUse is
      2          cursor c is select e.* from emp e;
      3          empRow  emp%RowType;
      4  begin
      5          open c;
      6          fetch c into empRow;
      7          --// not closing explicit cursor handle
      8          --// and going out-of-scope
      9  end;
    10  /
    Procedure created.
    // current session stats
    SQL> select b.name, a.value from v$mystat a, v$statname b where a.statistic# = b.statistic# and b.name like '%open%cursor%';
    NAME                                  VALUE
    opened cursors cumulative                91
    opened cursors current                    2
    // execute proc that "leaks" a cursor, 10000 times
    SQL> begin
      2          for i in 1..10000 loop
      3                  CursorUse;
      4          end loop;
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    // no errors due to cursor leakage
    // session stats: no cursor leakage occurred as
    // PL/SQL's garbage collector cleaned (and closed)
    // cursor handles when these became out-of-scope
    SQL> select b.name, a.value from v$mystat a, v$statname b where a.statistic# = b.statistic# and b.name like '%open%cursor%';
    NAME                                  VALUE
    opened cursors cumulative            10,095
    opened cursors current                    2
    SQL> So the cursor leakage you are seeing is caused by something else... so what else is part of the code, or the session, that you have not yet mentioned?

  • ORA-01000: maximum open cursors exceeded (please help / JDBC guru needed)

    ORA-01000: maximum open cursors exceeded
    I am getting this error when trying to execute 2,500 Sql DDL statements. I am executing the statement with:
    public boolean execute(String sql) ( like stmt.execute(sql); )
    After each execute() I close the statement ( like stmt.close() )
    I tried taking this a step further and decided to close and reopen the database connection after every 100 Sql statements processed and I still get this exception when continuing.
    ORA-01000: maximum open cursors exceeded
    Any help will be greatly appreciated. I need to figure how to close the cursors or how to finish processing all 2,500 statements. I do not have control over the init.ora file and can not increase the max cursors. I hope to figure out how to close the cursors so that no tweaking of the init.ora file is needed.
    ChrisTD

    Why dont you allocate dukes for this problem ???
    am getting this error when trying to execute 2,500 Sql DDL statements. I am executing the statement with:
    public boolean execute(String sql) ( like stmt.execute(sql); )
    After each execute() I close the statement ( like stmt.close() )
    What kind of DDL is that? are you using any cursor operations to fetch the data? What kind of query does this sql parameter contain?
    Look there is only 3 solutions for this kind of problem.
    1) shutdown the database and restart it.
    I dont think closing connection will shutdown the database as you
    told.
    2) shutdown the database access init.ora and increase the
    OPEN_CURSORS and then restart it.
    You told that you dont have access to init.ora.
    3) close every cursor that you open.(Probably you are not closing the cursor once you fetch the data).

  • Getting ORA-01000 : maximum open cursors exceeded  problem

    I am getting ORA-01000 : maximum open cursors exceeded problem in my piece of java code when the
    load is high .Open cursors is set to 1000 still getting the same problem .
    Basically i have to select some rows from a table which i am doing in A() function and process it and insert into
    another table which i do it in another function B() there is a update statement also in this fun.
    There is a particular business logic for which i need to call B() from the A() function
    which happens to be in the select result set like below
    A()
    query ="Select * from temp";
    while(rs.next)
    B();
    All the result sets are properly being closed that too in finally block.
    I dont see any other problem with code .Still I am gettin this cursor problem.
    Is some thing wrong with the design like calling a
    insert from a result set while loop or the update statement

    The code below is deleting fine. Check your $id is valid. I wonder if ADOdb has some quirks with binding and variable creation/destruction, similar to #1 in http://www.oracle.com/technology/tech/php/htdocs/php_troubleshooting_faq.html#bindvars
    <?php
    See ADOdb Tutorial for Oracle: http://phplens.com/lens/adodb/docs-oracle.htm
    drop table mytab;
    create table mytab (city varchar2(20), country_id varchar2(20));
    insert into mytab values ('SF', 'US');
    insert into mytab values ('Sydney', 'AU');
    insert into mytab values ('London', 'UK');
    commit;
    require_once("/home/cjones/public_html/php/adodb5/adodb.inc.php");
    $db = ADONewConnection("oci8");
    $db->Connect("//localhost/XE", "hr", "hrpwd");
    echo "Before:\n";
    $rs = $db->Execute("select city from mytab");
    while ($arr = $rs->FetchRow()) {
        echo $arr['CITY'] . "\n";
    $s = $db->Prepare("delete from mytab where country_id = :ci");
    $db->Parameter($s, $ci, 'ci');
    foreach (array('US', 'AU') as $ci) {
         $db->Execute($s);
    echo "After:\n";
    $rs = $db->Execute("select city from mytab");
    while ($arr = $rs->FetchRow()) {
        echo $arr['CITY'] . "\n";
    ?>There's another sample in the ADOdb OCI8 driver:
              Usage:
                   $stmt = $DB->Prepare("insert into table (col0, col1, col2) values (:0, :1, :2)");
                   $DB->Bind($stmt, $p1);
                   $DB->Bind($stmt, $p2);
                   $DB->Bind($stmt, $p3);
                   for ($i = 0; $i < $max; $i++) {     
                        $p1 = ?; $p2 = ?; $p3 = ?;
                        $DB->Execute($stmt);
                   }For queries I know this works. I haven't seen any examples that prepare once.
    $rs = $db->Execute("select city from mytab where country_id = :ci", array('ci' => 'UK'));
    while ($arr = $rs->FetchRow()) {
        echo $arr['CITY'] . "<br>\n";
    }

  • How to resolve the issue of ORA-01000: maximum open cursors exceeded

    Hi all,
    I'm new to Oracle, currently I write a simple java class to retrieve records form Oracle DB, but following error occurs:
    java.sql.SQLException: ORA-01000: maximum open cursors exceeded
    String sql = "select * from......";
    prepStmt = conn.prepareStatement(sql);
    prepStmt.setString(1, this.getId());
    rlt = prepStmt.executeQuery();
    while (rlt.next()) {
    try {
         rlt.getString("severity");
    rlt.getTimestamp("time_stamp");
    violationList.add(viol);
    } catch (Exception e) {                         
    When there are only few records in the table, it is ok, but if the result is large, occur the exception.
    Why and how to resolve?
    Thanks.
    Jane

    It is better to close statement using try...catch...finally , e.g.
    PreparedStatement objStmt = null;
    try
         objStmt = conn.prepareStatement(...);
         // ... do anything
    catch (Exception e)
         // ... exception handling
    finally
         // another try...catch block to handle exception during statement close
         try {   objStmt.close();   }     catch (Exception e) {   }
         objStmt = null;
    This would guarantee that statment object is being closed even though exception is thrown. (Don't wait for connection release by garbage collector)

Maybe you are looking for

  • Distinct and sum in alv report

    i have 6 row of 1 matnr and i have to display only 1 with the sum of each field example: 300032   3 4 1 300032   3 3 3 300032   2 2 2 i want <b>300032   8 9 7</b> how? thanks.

  • Message'there was an error opening this document.The file cannot be found'

    Using xp home and when I click to download the pdf file, it will give 3 options been 'open'/'save'/?. When I choose the 'open' option, it will give me the above message "there was an error opening this document.The file cannot be found" owever if I c

  • Best practice for developing and testing AIR iOS multitouch apps

    I'm considering switching our iPhone development practice from XCode/Objective C to AIR to leverage a larger pool of in house talent. The biggest concern I have right now is testing multitouch functionality - the prospect of having to do incremental

  • PSE9/Win 7: Edit/Copy does a Cut?

    I'm running PSE 9 on Windows 7. I must have forgotten how to do a copy/paste. Here is what I did: m - to select a rectangular area Edit/Copy - to make a copy of the contents of the Selection Click on the Move Tool. When I start to move my selection I

  • Can't open my website outside of my web server

    I have installed lion server on my mini. I want to use it to host my website url. www.bigislanprivatechef.com after setting up web server I can type the url into any of my browsers and my site fires right up. I can go to statcounter and see my hits r