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.
Similar Messages
-
Error while executing Procedure - ORA-06511: PL/SQL: cursor already open
I have successfully compiled the following procedure but when I execute it, following error occurs, please adv.
Thanks and Regards,
Luqman
create or replace
procedure TESTKIBOR
(contno in varchar)
AS
BEGIN
DECLARE cursor c1 is
SELECT * FROM KIBOR_SCHEDULE
WHERE CN=contno;
begin
OPEN C1;
FOR line IN c1 LOOP
update kibor_schedule
set lincome=line.Lincome,
expo=line.eXPO,
pport=line.pPORT
where cn=line.cn
and rno=line.rno;
END LOOP;
COMMIT;
close c1;
END;
END TESTKIBOR;
ERROR at line 1:
ORA-06511: PL/SQL: cursor already open
ORA-06512: at "MKTG.TESTKIBOR", line 6
ORA-06512: at "MKTG.TESTKIBOR", line 10
ORA-06512: at line 1Hi,
CREATE OR REPLACE PROCEDURE Testkibor
(contno IN VARCHAR)
AS
BEGIN
DECLARE
CURSOR c1 IS
SELECT *
FROM kibor_schedule
WHERE cn = contno;
BEGIN
--// OPEN c1; --no need to open if using for loop
FOR line IN c1 LOOP
UPDATE kibor_schedule
SET lincome = line.lincome,
expo = line.expo,
pport = line.pport
WHERE cn = line.cn
AND rno = line.rno;
END LOOP;
COMMIT;
--// CLOSE c1; -- no need for loop does it for you
END;
END testkibor;SS -
Help with "ORA-06511: PL/SQL: cursor already open"
I've tried numerous variations on this piece of code and I always get the same result. I'm sure this is painfully obvious to an experienced PL/SQL person.
Any help will be appreciated!
Thank You!
1 DECLARE
2 CURSOR EMP_CURSOR IS SELECT last_name from employees;
3 current_last_name varchar2(25);
4 BEGIN
5 IF EMP_CURSOR%ISOPEN
6 THEN
7 dbms_output.put_line ('cursor is already open');
8 close EMP_CURSOR;
9 END IF;
10 dbms_output.put_line ('opening cursor');
11 OPEN EMP_CURSOR;
12 FOR item in EMP_CURSOR LOOP
13 FETCH EMP_CURSOR INTO current_last_name;
14 EXIT WHEN EMP_CURSOR%NOTFOUND;
15 dbms_output.put_line (item.last_name);
16 END LOOP;
17 CLOSE EMP_CURSOR;
18* END;
19 /
DECLARE
ERROR at line 1:
ORA-06511: PL/SQL: cursor already open
ORA-06512: at line 2
ORA-06512: at line 12Mathieu,
Log in as anotherSchema and grant select on 'IDsTable' to the current user.
SQL> r
1 create or replace function f1(theID varchar2) return mytype pipelined is
2 out varchar2(30);
3 cursor myCursor (x varchar2) is select * from scott.emp where job=x;
4 begin
5 for rec in myCursor(theID) loop
6 pipe row(rec.ename);
7 end loop;
8 return;
9* end;
Warning: Function created with compilation errors.
SQL> show errors
Errors for FUNCTION F1:
LINE/COL ERROR
3/33 PL/SQL: SQL Statement ignored
3/53 PL/SQL: ORA-00942: table or view does not exist
6/1 PL/SQL: Statement ignored
6/10 PLS-00364: loop index variable 'REC' use is invalid
SQL> connect scott
Enter password: *****
Connected.
SQL> grant select on emp to testuser;
Grant succeeded.
SQL> connect testuser
Enter password: ****
Connected.
SQL> create or replace function f1(theID varchar2) return mytype pipelined is
2 out varchar2(30);
3 cursor myCursor (x varchar2) is select * from scott.emp where job=x;
4 begin
5 for rec in myCursor(theID) loop
6 pipe row(rec.ename);
7 end loop;
8 return;
9 end;
10 /
Function created.
SQL> disconnect
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.3.0 - Production
SQL> -
Cursors remained open after closing connection
I am using OC4J 10g (Application Server) and Oracle10g DB. OC4J is maintaining the connection pool(com.evermind.sql.DriverManagerDataSource). I get the connection from pool and call DB procedure, then close resultset, statement and connection. It closes the opened cursors against resultset. But left some implicit cursors opened and never closed so cursor count is going to increase.
If i dont use pool no cursor remained open and count is zero. It means the cursors of pooled connections are not closed.
wait-timeout="60"
min-connections="5"
max-connections="100"
inactivity-timeout="15"
<property name="stmt-cache-size" value="2000"/>
TahirHi Justin,
Thnx for your reply and you're understanding is correct but the problem I face is when multiple concurrent users access the JSP page from which I'm actually calling the servlet to retrieve the image, the number of cursors being left open increases. As the load on the page increases (i.e. no of usesrs increase) oracle seems to have problems in garbage collecting the open cursors ... which eventually leads it to throw maximum cursors exceeded exceptions.
Any suggestions ?
-Athar -
Getting error --- ORA-06511: PL/SQL: cursor already open
I have the following code for a Apex(Application Express) project I am developing.
declare
mail_id varchar2(100);
min_skill_cnt number;
skill_cde varchar2(30);
total_leave number;
toal_emp number;
cursor cur is
select S_EMP_EMAIL
from EMP_SKILLS_INFO where SKILLCODE='MGR' and S_EMP_EMAIL = lower(:APP_USER) ;
cursor minskill is
select skill_code,MINRQMT_AM
from skills_code_info
where skill_code in (select skillcode from emp_skills_info where S_EMP_EMAIL = lower(:APP_USER));
cursor leavecnt(v_skill IN VARCHAR2) is
select count(*) from emp_leave_info
where leave_date = :P24_LEAVE_DATE
and emp_email IN (select S_EMP_EMAIL from EMP_SKILLS_INFO where SKILLCODE = v_skill);
cursor empcnt(v_skills IN VARCHAR2) is
select count(*) from EMP_SKILLS_INFO
where SKILLCODE = v_skills;
begin
open cur;
open minskill;
LOOP
fetch minskill into skill_cde,min_skill_cnt;
exit when minskill%NOTFOUND;
open leavecnt(skill_cde);
fetch leavecnt into total_leave;
open empcnt(skill_cde);
fetch empcnt into toal_emp;
IF toal_emp-total_leave < min_skill_cnt
then
apex_mail.send(
p_to => :APP_USER ,
p_from => '[email protected]',
p_cc => NULL,
p_body => '***** This is a system generated message, please do not reply to this *****'||
chr(10) || utl_tcp.crlf || 'Please review the current skill as '||:APP_USER||' is on leave'||
chr(10) || utl_tcp.crlf ||'Thanks',
p_subj => 'Skill code alert' );
end if;
END LOOP;
close empcnt;
close leavecnt;
close minskill;
close cur;
end;
=======================
Ideally this should send email to managers when a particular skill is running short when employee applies for leave.
I am getting error that cursor is already open when I run this code. I am not sure which cursor or where it is picking open cursor command.
Any inputs will be appreciated.LOOP
FETCH minskill
INTO skill_cde, min_skill_cnt;
EXIT WHEN minskill%NOTFOUND;
OPEN leavecnt (skill_cde); --- here you open.. in a loop and not close inside loop
FETCH leavecnt INTO total_leave;
OPEN empcnt (skill_cde);--- here you open.. in a loop and not close inside loop
FETCH empcnt INTO toal_emp;
IF toal_emp - total_leave < min_skill_cnt
THEN
apex_mail.
send (
p_to => :APP_USER,
p_from => '[email protected]',
p_cc => NULL,
p_body => '***** This is a system generated message, please do not reply to this *****'
|| CHR (10)
|| UTL_TCP.crlf
|| 'Please review the current skill as '
|| :APP_USER
|| ' is on leave'
|| CHR (10)
|| UTL_TCP.crlf
|| 'Thanks',
p_subj => 'Skill code alert');
END IF;
END LOOP; -
SQL Connections remain open after Crystal Report closes
I am wirting an interface to use the crystal report viewer to print reports, connecting to a Progress Open Edge 10.1B database. From our application we declare the application, report, exportoptions and connectionproperties objects and pass these to the crystal reports viewer. Once the report is printed we release the objects and set their variables for null. However we are finding that the SQL connection to the database is remaining connected and we can only release the connection by manually going in a disconnecting.
I have read in forums that people use .dispose or .close to release the connection, however we do not have access to these methods as we do not use .NET. Are there any methods we can use to disconnect these sql connections?Hi Dean,
Moved to the Legacy Application forums. Likely using the RDC as your report engine.
You should still be able to close and dispose of the report objects. They are not specific to .NET.
In VB it would look something like these lines::
crReport.Close
Set CrystalActiveXReportViewer1.ReportSource = Nothing
Set crReport = Nothing
Once the report is closed it should disconnect from the DB. If you close the application does that disconnect?
Have you looked on 4GL's site for info on how to?
Thank you
Don -
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 PMPL/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 ORA-06512
Hi,
An exception error ccurred as below while trying to map a column.
Exception oracle.apps.bne.exception.BneSQLException: SQL Exception in BneFlex.validateSegs: java.sql.SQLException: ORA-01000: maximum open cursors exceeded ORA-06512: at "APPS.FND_MESSAGE", line 525 ORA-06512: at "APPS.FND_MESSAGE", line 565 ORA-06512: at "APPS.FND_MESSAGE", line 654 ORA-06512: at "APPS.FND_MESSAGE", line 766 ORA-06512: at "APPS.FND_MESSAGE", line 741 ORA-06512: at "APPS.FND_FLEX_KEYVAL", line 324 ORA-06512: at line 1 occurred trying to map column: Expense Account.
In alert log file:
Errors in file /vol01/oracle/SIT/db/tech_st/10.2.0/admin/SIT_sit/udump/sit_ora_7
04744.trc:
ORA-07445: exception encountered: core dump [] [] [] [] [] []
ORA-00604: error occurred at recursive SQL level 1
ORA-01000: maximum open cursors exceeded
ORA-01000: maximum open cursors exceeded
Thanks
Edited by: userpat on Aug 15, 2010 5:32 AMHi,
The issue is different this time after restarting application and database find below.
An exception occured trying to map a column
Exception java.lang.ArrayIndexOutOfBoundsException:Array index out of range:1
occured trying to map column:Category
in bne.log
8/18/10 12:08 PM AJPRequestHandler-ApplicationServerThread-2 ERROR BneP
arentMenuResolver.getMenuItem() MENU 101:BUDGET_NOTE - Menu item excluded becaus
e IntegratorAppId and Code does not match that of the Top-Most Menu Item or curr
ent Integrator: 140:FA_MASS_ADDITIONSThe same error is reported in Note: 954462.1 (which is referenced above).
And also let me clear one doubt. v$open_cursors view is used for what?. The total number of count v$open_cursors is 60,000 whereas the parameter is defined only 2000 in the Instance.Cursors Remain Open (in V$OPEN_CURSOR View) after being Closed [ID 1020427.102]
Monitoring Open Cursors & Troubleshooting ORA-1000 Errors [ID 76684.1]
V$OPEN_CURSOR
http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/dynviews_2008.htm#REFRN30166
Thanks,
Hussein -
Ref Cursor over Implicit and explicit cursors
Hi,
In my company when writing PL/SQL procedure, everyone uses "Ref Cursor",
But the article below, says Implicit is best , then Explicit and finally Ref Cursor..
[http://www.oracle-base.com/forums/viewtopic.php?f=2&t=10720]
I am bit confused by this, can any one help me to understand this?
ThanksSeshuGiri wrote:
In my company when writing PL/SQL procedure, everyone uses "Ref Cursor",
But the article below, says Implicit is best , then Explicit and finally Ref Cursor..
[http://www.oracle-base.com/forums/viewtopic.php?f=2&t=10720]
I am bit confused by this, can any one help me to understand this?There is performance and there is performance...
To explain. There is only a single type of cursor in Oracle - that is the cursor that is parsed and compiled by the SQL engine and stored in the database's shared pool. The "+client+" is then given a handle (called a SQL Statement Handle in many APIs) that it can use to reference that cursor in the SQL engine.
The performance of this cursor is not determined by the client. It is determined by the execution plan and how much executing that cursor cost ito server resources.
The client can be Java, Visual Basic, .Net - or a PL/SQL program. This client language (a client of SQL), has its own structures in dealing with that cursor handle received from the SQL engine.
It can hide it from the developer all together - so that he/she does not even see that there is a statement handle. This is what implicit cursors are in PL/SQL.
It can allow the developer to manually define the cursor structure - this is what explicit cursors, ref cursors, and DBMS_SQL cursors are in PL/SQL.
Each of these client cursor structures provides the programmer with a different set of features to deal with SQL cursor. Explicit cursor constructs in PL/SQL do not allow for the use of dynamic SQL. Ref cursors and DBMS_SQL cursors do. Ref cursors do not allow the programmer to determine, at run-time, the structure of the SQL projection of the cursor. DBMS_SQL cursors do.
Only ref cursors can be created in PL/SQL and then be handed over to another client (e.g. Java/VB) for processing. Etc.
So each of the client structures/interfaces provides you with a different feature set for SQL cursors.
Choosing implicit cursors for example does not make the SQL cursor go faster. The SQL engine does not know and does not care, what client construct you are using to deal with the SQL cursor handle it gave you. It does not matter. It does not impact its SQL cursor performance.
But on the client side, it can matter - as your code in dealing with that SQL cursor determines how fast your interaction with that SQL cursor is. How many context switches you make. How effectively you use and re-use the SQL (e.g. hard parsing vs soft parsing vs re-using the same cursor handle). Etc.
Is there any single client cursor construct that is better? No.
That is an ignorant view. The client language provides a toolbox, where each tool has a specific application. The knowledgeable developer will use the right tool for the job. The idiot developer will select one tool and use it as The Hammer to "solve" all the problems. -
Query to find which past ses caused ORA-1652: unable to extend temp segment
Hi,
I m trying to get information on the sessions/sql query that have cause ORA-1652: unable to extend temp segment from past 2 days. Basically need to know which all sessions in past 2 days have caused ORA-1652: unable to extend temp segment.
I have generated the AWR report but not able to figure it out which sessions caused this error.
Thanks in advance913410 wrote:
Hi,
I m trying to get information on the sessions/sql query that have cause ORA-1652: unable to extend temp segment from past 2 days. Basically need to know which all sessions in past 2 days have caused ORA-1652: unable to extend temp segment.
I have generated the AWR report but not able to figure it out which sessions caused this error.
Thanks in advance
01652, 00000, "unable to extend temp segment by %s in tablespace %s"
// *Cause: Failed to allocate an extent of the required number of blocks for
// a temporary segment in the tablespace indicated.
// *Action: Use ALTER TABLESPACE ADD DATAFILE statement to add one or more
// files to the tablespace indicated. -
Please help me for resolving this Error.
I got This Error while Web Load TEsting.
java.sql.SQLException: ORA-01000: maximum open cursors exceeded ORA-06512: at "IADMIN.ADM_ADMIN_ISMART_PCK", line 269 ORA-06512: at line 1I also faced similar problem - and solved as following:
java.sql.PreparedStatement pStmt = null;
ResultSet rs, rs_opr;
try {
query = "select ..."
pStmt = conn.prepareStatement (query); // first instance of the PreparedStatement
pStmt.setInt (1, rq_count);
pStmt.setString (2, rqid);
rs = pStmt.executeQuery ();
if (rs.next()) {
plant_nm = rs.getString("PLANT_NM");
rs.close();
pStmt.close(); // this was done only at the last time (added here and solved)
query = "select ..."
pStmt = conn.prepareStatement (query); // second instance of the PreparedStatement
pStmt.setInt (1, rq_count);
pStmt.setString (2, rqid);
rs = pStmt.executeQuery ();
if (rs.next()) {
Var2 = rs.getString("Vari1ble_2");
rs.close();
pStmt.close(); // this was done only at the last time (added here and solved)
query = "select ..."
pStmt = conn.prepareStatement (query); // third instance of the PreparedStatement
pStmt.setInt (1, rq_count);
pStmt.setString (2, rqid);
rs = pStmt.executeQuery ();
if (rs.next()) {
Var3 = rs.getString("Variable_3");
rs.close();
pStmt.close(); // this was done only here -- added 2 times as above
} -
Urgent!!! ORA-01000: maximum open cursors exceeded
hello guys, I have done a search in this forum and read plenty of threads, but I didn't find any official answer to this question. In my code, I have closed all the statements and resultsets after using them, but I still got the MAXIMUM OPEN CURSOR exceed exception.
I am not sure whether I close the stmt and rs in the right way. Which one should I close first, the statement or the resultset? Does the order matters??? Thanks a million you can have a good way to solve this problem!!!
Statement st= null;
ResultSet rs = null;
try{
.......// some code
}catch(SQLException sqle){
finally{
if(st!=null)
st.close();
if(rs!=null)
rs.close();The connection I am using is from a pool. I can't close the connection because I need to return it to the pool...
BTW, I just solved the ORA-01100 problem. Here is what I did, I hope it may be helpful.
The original code I have looks like this. That's the code that generates the ORA-01100 exception.
Connection conn = null;
PreparedStatement pstmt= null;
ResultSet rs = null;
try{
conn = Pool.getConection(); // get connection from pool
String sql = "someSQL";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
// do something with the resultset
// here, I reuse the pstmt and rs.
// I think that is what cause the ORA-01000 problem
// because I don't think there is anything wrong
// with the finally block
sql = "another query";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
// do something with the resultset
}catch(SQLException sqle) {
// ignore.......
} finally {
try
if(rs!=null) rs.close();
if(pstmt!=null) pstmt.close();
if(conn != null) Pool.returnConnection(conn); // return connection to pool
} catch(Exception fe) {
}Here is the fixed version of the code that eliminates the ORA-01000 error in my case. If in your code, you re-use your statements, preparedstatments or results, You can try it too.
Connection conn = null;
PreparedStatement pstmt= null;
ResultSet rs = null;
try{
conn = Pool.getConection();
String sql = "someSQL";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
// do something with the resultset
// In the fixed version, I only added the block of
// code below and it solves the problem.
// Before I re-use the preparedstatments,
// statement, and result for a new query,
// I closed them and set them to null.
try {
if(rs != null) rs.close();
if(pstmt != null) pstmt.close();
rs = null;
pstmt = null;
} catch(Exception ie) {
// ignore
sql = "another query";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
// do something with the resultset
}catch(SQLException sqle) {
// ignore.......
} finally {
try
if(rs!=null) rs.close();
if(pstmt!=null) pstmt.close();
if(conn != null) Pool.returnConnection(conn); // return connection to pool
} catch(Exception fe) { -
ORA-01000: Too many open cursors -- Need Help
Hi All,
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
I am getting error ora-01000 for the following procedures gather stats
Could you please guide how to get-rid-off this error.
thanks in advance;
CREATE OR REPLACE PROCEDURE SHEMA_NAME ANALYZE_TABLES IS
rec_table_name VARCHAR2 (30);
CURSOR c1
IS
SELECT table_name
FROM USER_tables; ------ 18000 table for this cursor
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO rec_table_name;
EXIT WHEN c1%NOTFOUND;
-- block was hereÿÿÿ
BEGIN
DBMS_STATS.
GATHER_TABLE_STATS (
OWNNAME => 'SHEMA_NAME',
TABNAME => rec_table_name,
PARTNAME => NULL,
ESTIMATE_PERCENT => 30,
METHOD_OPT => 'FOR ALL COLUMNS SIZE AUTO',
DEGREE => 5,
CASCADE => TRUE);
END;
END LOOP;
CLOSE c1;
EXCEPTION
WHEN OTHERS
THEN
raise_application_error (
-20001,
'An error was encountered - ' || SQLCODE || ' -ERROR- ' || SQLERRM);
END;Look at the following:
SQL> begin
2 raise no_data_found;
3 end;
4 /
begin
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 2
The error code the caller executing this code receive is -01403. A unique error number that has a known and specific meaning.
In addition, the error stack tells the caller that this unique error occurred on line 2 in the source code.
The caller knows EXACTLY what the error is and where it occurred.
SQL> begin
2 raise no_data_found;
3 exception when OTHERS then
4 raise_application_error(
5 -20000,
6 'oh damn some error happened. the error is '||SQLERRM
7 );
8 end;
9 /
begin
ERROR at line 1:
ORA-20000: oh damn some error happened. the error is ORA-01403: no data found
ORA-06512: at line 4
In this case the caller gets the error code -20000. It is meaningless as the same error code will be use for ALL errors (when OTHERS). So the caller will never know what the actual real error is.
For the caller to try and figure that out, it will need to parse and process the error message text to look for the real error code. A very silly thing to do.
In addition, the error stack says that the error was caused by line 4 in the code called.. except that this is the line that raised the meaningless generic error and not the actual line causing the error.
There are 3 basic reasons for writing an exception handler:
- the exception is not an error
- the exception is a system exception (e.g. no data found) and needs to be turned into meaningful application exceptions (e.g. invoice not found, customer not found, zip code not found, etc)
- the exception handler is used as a try..finally resource protection block (which means it re-raises the exception)
If your exception handler cannot tick one of these three reasons for existing, you need to ask yourself why you are writing that handler. -
ORA-01000: maximum open cursors exceeded
I ran into this Too many Open Cursors Issue
My environment is
WebLogic 6.1 SP2
Oracle 8.1.7.3.0
JDBC Thin Driver
WebLogic Connection Pools
Tried all the solutions given in the news group for issues, none seemed to work,
so deviced a work around.
just wanted to know if there is a better solution that works.
or else we will go ahead with the workaround...
Explanation follows...
When we work with the weblogic connection pool
Using the WebLogic Pool Driver, we ask for a connection from Weblogic connection
pool.
WebLogic connection pool uses the Oracle Driver to connect to the Oracle Database.
creates a connection and provides it to us.
as we work with this connection, we create prepared statements, execute them etc.
etc. and this will create cursors in the oracle database.
now when we close the connection from our program, what gets closed is the connection
created between our program and the WebLogic Connection Pool
but the connection between the WebLogic Connection Pool and the Oracle database still
remains open, well, there is nothing wrong in that after all that is how connection
pool has to work.
but the issue here is the open cursors that are cached in oracle when we created
statements are not closed even after we close the statements and the connections,
since according to oracle, the connection is still active becuase WebLogic connection
pool is still maintaining the connection. and oracle will clear that only when the
connection is closed with it.
WebLogic pool driver is supposed to clear up the open cursor cache. but i guess it
is not doing it.
I did some R&D and tried out the following solutions and they dont seem to solve
the issue. (Most of them were picked up from the News groups)
1. Include the latest Oracle type 4 driver in class path before the other classes
2. Put a Connection.rollback before closing connection
3. Use the Oracle Driver directly bypassing the Connection Pool. (This works... but
we cant do that becuase we are using connection pools to handle connection.)
So I came up with the following work around.
Whenever a connection is created from oracle, internally the driver creates a session
with oracle.
when weblogic pool driver creates a session it uses an ORACLE session parameter SESSION_CACHED_CURSORS
I guess WebLogic sets it to a high number. But there has to be a parameter which
we can configure to control this when we create out connection pool. the closest
parameter was found to be "Prepared Statement Cache Size" but even after making it
0 it doesnt seem to improve the situation.
so, to override the SESSION_CACHED_CURSORS in our connection. every time we get a
connection we have to execute a query to alter the session paramater SESSION_CACHED_CURSORS
as follows
woConn = java.sql.DriverManager.getConnection(DCConstants.DC_JDBC_URL);
try
Statement woTmpStmt = woConn.createStatement();
woTmpStmt.execute("ALTER SESSION SET SESSION_CACHED_CURSORS = 0");
woTmpStmt.close();
catch(SQLException woSQLEx)
DCDebug.logInfo("DCDataFactory","Unable to alter session");
regards
GulamHi. If you'e turned off our statement cache (by setting it's size to zero),
then it's a DBMS-side issue only. When you return a connection to the
pool (by closing it), we will close any statements and result sets you
had created but not closed, so we do all we can. In fact if you left
the connection in an autoCommit(false) mode, we do the rollback for you
too. Besides setting that DBMS-side option you do with SQL, the only
other option I see is to configure your DBMS/session info for Oracle,
to allow more open cursors per connection than you currently allow.
Joe Weinstein at B.E.A.
Gulam Dasthagir wrote:
I ran into this Too many Open Cursors Issue
My environment is
WebLogic 6.1 SP2
Oracle 8.1.7.3.0
JDBC Thin Driver
WebLogic Connection Pools
Tried all the solutions given in the news group for issues, none seemed to work,
so deviced a work around.
just wanted to know if there is a better solution that works.
or else we will go ahead with the workaround...
Explanation follows...
When we work with the weblogic connection pool
Using the WebLogic Pool Driver, we ask for a connection from Weblogic connection
pool.
WebLogic connection pool uses the Oracle Driver to connect to the Oracle Database.
creates a connection and provides it to us.
as we work with this connection, we create prepared statements, execute them etc.
etc. and this will create cursors in the oracle database.
now when we close the connection from our program, what gets closed is the connection
created between our program and the WebLogic Connection Pool
but the connection between the WebLogic Connection Pool and the Oracle database still
remains open, well, there is nothing wrong in that after all that is how connection
pool has to work.
but the issue here is the open cursors that are cached in oracle when we created
statements are not closed even after we close the statements and the connections,
since according to oracle, the connection is still active becuase WebLogic connection
pool is still maintaining the connection. and oracle will clear that only when the
connection is closed with it.
WebLogic pool driver is supposed to clear up the open cursor cache. but i guess it
is not doing it.
I did some R&D and tried out the following solutions and they dont seem to solve
the issue. (Most of them were picked up from the News groups)
1. Include the latest Oracle type 4 driver in class path before the other classes
2. Put a Connection.rollback before closing connection
3. Use the Oracle Driver directly bypassing the Connection Pool. (This works... but
we cant do that becuase we are using connection pools to handle connection.)
So I came up with the following work around.
Whenever a connection is created from oracle, internally the driver creates a session
with oracle.
when weblogic pool driver creates a session it uses an ORACLE session parameter SESSION_CACHED_CURSORS
I guess WebLogic sets it to a high number. But there has to be a parameter which
we can configure to control this when we create out connection pool. the closest
parameter was found to be "Prepared Statement Cache Size" but even after making it
0 it doesnt seem to improve the situation.
so, to override the SESSION_CACHED_CURSORS in our connection. every time we get a
connection we have to execute a query to alter the session paramater SESSION_CACHED_CURSORS
as follows
woConn = java.sql.DriverManager.getConnection(DCConstants.DC_JDBC_URL);
try
Statement woTmpStmt = woConn.createStatement();
woTmpStmt.execute("ALTER SESSION SET SESSION_CACHED_CURSORS = 0");
woTmpStmt.close();
catch(SQLException woSQLEx)
DCDebug.logInfo("DCDataFactory","Unable to alter session");
regards
Gulam -
ORA-00604:error occurred at recursive SQL level1 ORA-01000:maximum open cur
Dear Experts,
I got Error During WebLoad Testing.
Please give me solution.
java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1 ORA-01000: maximum open cursors exceededIt depends on how may cursors are used in your program and the parameter value for OPEN_CURSORS. If it is not possible to reduce the number cursors used in the program increase the OPEN_CURSORS value.
regards
Maybe you are looking for
-
Cannot print with HP Deskject 1515 in Windows 8.1
Hi, I bought a brand-new HP Deskjet All-in-One 1515. I installed the HP software and the drivers on my Windows 8.1 laptop, I updated them, and I run the Scan Doctor...everything seemed to be fine (i.e. I print a test-page within the Scan Doctor, I ca
-
[Solved] mpv drops frames intermittently
I'm using openbox with compton as my compositor. My graphics card is an ATI 5450M and I use it with the open source driver. I seem to be having a very weird problem in which mpv (or mplayer, for that matter) skips frames while playing. It's not a who
-
Chart horizontal axis show whole year
Hi All, How to display whole year month as horizontal axis even if no data? for example, currently I have data for FY13 up to Jan 13, no data for Feb 13, Mar 13, Apr 13, May 13 and Jun 13 yet, in the chart it will automatically showing horizontal axi
-
EIS error - "Unable to set locale for GlobalC"
Hello all! I'm working with Oracle Performance Scorecard and Oracle Integration Services to generate an Essbase cube. I'm not able no generate my cube from HPS even it doesn't showing any error in the screen but in the HPS log it shows the error mess
-
What are the differences between ALEREMOTE and BWREMOTE?
I often get confused about the above two concepts. Would you please help explain? Thanks a lot!