Closing a cursor.
Hi Friends,
In the execution of a standard SAP Function Module one of my programs is generating a dump stating the reason of
SAPSQL_CURSOR_ALREADY_OPEN.
How can I close this cursor and again run the program. Or can the Basis guys delete them.
Thanks and Regards,
Arunava
Hi,
This is cause of you are trying to open a cursor that is already open. Check the code that is giving the problem. Put the logic as Open cursor then close it before opening it again.
Or work with the original one do not open it again.
Regards,
amit
Similar Messages
-
I have a drag image application and I wanted to use the open and closed hand cursors to move the image about. It seems there is no easy way of accessing these in Java. After searching for cursor names etc.. I decided to hard code the cursors from the .gif image. Also I didn't want the .GIFs as files as this adds to loading problems so I ended up using arrays of pixels that took a little while to enter.
I'm giving you the code if you ever need to use it as I typed it in and wouldn't want anyone else to have to do the same.
int curWidth=32;
int curHeight=32;
int curCol;
Image img;
int x,y;
int closed_black[] = { 6,5,7,5,9,5,10,5,12,5,13,5,5,6,8,6,11,6,14,6,
15,6,5,7,14,7,16,7,6,8,16,8,5,9,6,9,16,9,4,10,
16,10,4,11,16,11,4,12,15,12,5,13,15,13,6,14,14,14,
7,15,14,15,7,16,14,16,0};
int closed_white[] = { 6,4,7,4,9,4,10,4,12,4,13,4,5,5,8,5,11,5,14,5,15,5,
4,6,6,6,7,6,9,6,10,6,12,6,13,6,16,6,4,7,15,7,17,7,
5,8,17,8,4,9,17,9,3,10,5,10,15,10,17,10,3,11,17,11,
3,12,16,12,4,13,16,13,5,14,15,14,6,15,15,15,6,16,
15,16,7,17,14,17,0};
int closed_whiteruns[] = {6,13,7,15,7,15,5,15,5,15,5,14,6,14,7,13,8,13,8,13,0};
int open_black[] = { 10,3,11,3,6,4,7,4,9,4,12,4,13,4,14,4,5,5,8,5,9,5,12,5,
15,5,5,6,8,6,9,6,12,6,15,6,17,6,6,7,9,7,12,7,15,7,16,7,18,7,
6,8,9,8,12,8,15,8,18,8,4,9,5,9,7,9,15,9,18,9,3,10,6,10,7,10,
18,10,3,11,7,11,17,11,4,12,17,12,5,13,17,13,5,14,16,14,6,15,
16,15,7,16,15,16,8,17,15,17,8,18,15,18,0};
int open_white[] = {10,2,11,2,6,3,7,3,9,3,12,3,13,3,5,4,8,4,10,4,11,4,15,4,
4,5,6,5,7,5,10,5,11,5,13,5,14,5,16,5,17,5,4,6,6,6,7,6,10,6,
11,6,13,6,14,6,16,6,18,6,5,7,7,7,8,7,10,7,11,7,13,7,14,7,17,7,
19,7,4,8,5,8,7,8,8,8,10,8,11,8,13,8,14,8,16,8,17,7,19,8,3,9,6,9,
16,9,17,9,19,9,2,10,4,10,5,10,19,10,2,11,18,11,3,12,18,12,4,13,
18,13,4,14,17,14,5,15,17,15,6,16,16,16,7,17,18,17,7,18,16,18,
8,19,15,19,0};
int open_whiteruns[] = {9,14,8,17,4,16,5,16,6,16,6,15,7,15,8,14,9,14,9,14,0};
int pix[] = new int[curWidth*curHeight];
for(y=0; y<=curHeight; y++) for(x=0; x<=curWidth; x++) pix[y+x]=0; // all points transparent
// black pixels
curCol=Color.black.getRGB();
int n=0;
while(closed_black[n]!=0)
pix[closed_black[n++]+closed_black[n++]*curWidth]=curCol;
// white pixels
curCol=Color.white.getRGB();
n=0;
while(closed_white[n]!=0)
pix[closed_white[n++]+closed_white[n++]*curWidth]=curCol;
// white pixel runs
n=0;
y=7;
while(closed_whiteruns[n]!=0) {
for(x=closed_whiteruns[n++];x<closed_whiteruns[n];x++)
pix[x+y*curWidth]=curCol;
n++; y++;
img = createImage(new MemoryImageSource(curWidth,curHeight,pix,0,curWidth));
closedhandCursor = Toolkit.getDefaultToolkit().createCustomCursor(img,new Point(5,5),"closedhand");
for(y=0; y<=curHeight; y++) for(x=0; x<=curWidth; x++) pix[y+x]=0; // all points transparent
// black pixels
curCol=Color.black.getRGB();
n=0;
while(open_black[n]!=0)
pix[open_black[n++]+open_black[n++]*curWidth]=curCol;
// white pixels
curCol=Color.white.getRGB();
n=0;
while(open_white[n]!=0)
pix[open_white[n++]+open_white[n++]*curWidth]=curCol;
// white pixel runs
n=0;
y=9;
while(open_whiteruns[n]!=0) {
for(x=open_whiteruns[n++];x<open_whiteruns[n];x++)
pix[x+y*curWidth]=curCol;
n++; y++;
img = createImage(new MemoryImageSource(curWidth,curHeight,pix,0,curWidth));
openhandCursor = Toolkit.getDefaultToolkit().createCustomCursor(img,new Point(5,5),"openhand");
setCursor(openhandCursor);you need to define openhandCursor and closedhandCursor with your other cursor definitions (I made them default to start with) and then just use setcursor as normal. There must be an easier way to do this!
p.s. thanks to Martin Zvarik for the original code here: http://www.jguru.com/faq/view.jsp?EID=9958Hi,
you can use the same query...Also check the new code after the select..
SELECT BUKRS BELNR GJAHR <b>BSTAT</b>
FROM BKPF
INTO TABLE T_BKPF
WHERE BUKRS = P_BUKRS
AND BSTAT IN ( ' ' , 'A' ) " ' ' - Normal document, A - Parked doc
AND BLART = P_BLART
AND CPUDT IN SO_CPUDT " Selection screen input.
IF NOT T_BKPF[] IS INITIAL.
SELECT BUKRS BELNR GJAHR BUZEI EBELN AUGBL AUGBT
INTO TABLE T_BSEG
FOR ALL ENTRIES IN T_BKPF
WHERE BUKRS = T_BKPF-BUKRS
AND BELNR = T_BKPF-BELNR
AND GJAHR = T_BKPF-GJAHR
AND EBELN IN SO_EBELN " selection-screen input
ENDIF.
LOOP AT T_BKPF.
Parked
IF T_BKPF-BSTAT = 'A'.
WRITE: / T_BKPF-BELNR , ' - Parked'.
process the next record.
CONTINUE.
ENDIF.
Check for Open / Closed.
LOOP AT T_BSEG WHERE BELNR = T_BKPF-BELNR
AND BUKRS = T_BKPF-BUKRS
AND GJAHR = T_BKPF-GJAHR
AND AUGBL <> ' '.
EXIT.
ENDLOOP.
If the return code is 0 then the document is cleared..
IF sy-subrc = 0.
WRITE: / T_BKPF-BELNR , ' - Closed'.
Else the document is not cleared.
ELSE.
WRITE: / T_BKPF-BELNR , ' - Open'.
ENDIF.
ENDLOOP.
Thanks,
Naren -
I have read that, the cursor in a for loop will be opened and closed automatically. Will that be the same in the case of the code given below, where we are declaring the cursor before the for loop ?
-- Code
create or replace procedure test
as
begin
-- some statements
-- begin of another block
declare
cursor v_cursor is Select * from Employee;
begin
for cur in v_cursor loop
-- loop statements
end loop;
end;
end test; -- end of procedure
Thanks in advance ..for more information on cursor for loop follow the link
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/01_oview.htm#767 -
Hi,
I've one doubt. If we've opened any cursor in pl/sql session, & did not close it during code run, is there any chance that the cursor will remain open?
My problem here is as below:
We're calling a pl/sql package through a java based application, & the connection will automatically close oracle session after 1/2 hour inactivity. But the oracle session is not getting closed. Probability is that the oracle session is still active(which may be because of open cursor)
Inside a package, a open cusror call was made, but there was no close cursor statement. Can this statement create any problem like above or is there any other possibility.
Thanks
DeepakThe issue seems to be a concern that rows listed in V$OPEN_CURSOR are currently open. My experience is that that may not necessarily be the case.
While rows in V$OPEN_CURSOR were probably open sometime in the recent past, there's no guarantee they are open RIGHT NOW. Sometimes entries get left in the V$ tables long after I think they should be aged out (this morning I found a last executed time in V$SYSSTAT from 2 days ago). Conversely, sometimes I cannot find things I am looking for that are running right now.
I agree with Rob's assessment that if you're not using a cursor it needs to be closed to release system resources. -
Hi All,
after closed all connection & resultSet, CallableStatement object and then set it to be as NULL in my application
but a lot of cursor still open. how can be solve this problem ?
Can anyone tell me....?
Pls reply........Gangadhar Reddy wrote:
I used SYS REFCURSOR and was able to implement successfully.How many times did you run this successful implementation that does not use bind variables?
Because this is what will happen when it runs a lot.
http://download.oracle.com/docs/cd/E11882_01/server.112/e17766/e2100.htm#sthref1874
http://forums.oracle.com/forums/search.jspa?q=%2BORA-04031%20%2Bbind&objID=c84&dateRange=all&rankBy=10001&start=30
And you will have to regularly restart the server, or possibly slightly less invasive, flush the shared pool.
Flushing Shared Pool regularly
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1516005546092
>
Ok, this is an easy one to diagnose.
You are not using bind variables. This is terrible. Flushing the shared pool is a bad
solution -- you are literally killing the performance on your box by not using them.
If I was to write a book on how to build non scalable applications in Oracle, this
would be the first and last chapter. This is a major cause of performance issues and a
major inhibitor of scalability in Oracle. The way the Oracle shared pool (a very
important shared memory data structure) operates is predicated on developers using bind
variables. If you want to make Oracle run slowly, even grind to a total halt just
refuse to use them.
>
But, please feel free to go ahead with this successful implementation.
I just hope anyone else who reads this doesn't make the same mistake. -
hi,
Assume, i have a function which returns a REF CURFOR. it is calling from JAVA.
After DB connection close on JAVA side, is the cursor close simultaneously?
if not, What must be done to close the cursor from Java side?If you have a connection pool, closing a connection doesn't really close the physical database connection, so Oracle doesn't have a chance to clean up any cursor handles your application might have left open. If you're opening and closing physical database connections from JDBC rather than going through a connection pool, you should still be closing your ResultSet objects, but mistakes where cursors get left open are covered up when you close the physical connection. When you're using a connection pool, though, you don't have that behavior to fall back on, so it is more critical that you make sure to close any open ResultSet objects.
Justin -
Listed below is my code. I get the following errors when trying to execute
Error(35,29): PLS-00103: Encountered the symbol "@" when expecting one of the following: mod <an identifier> <a double-quoted delimited-identifier> <a bind variable> current sql execute forall merge pipe
on this block [BEGIN
OPEN source_table;
FETCH source_table INTO @FIN;]
Please any ideas will be helpful.
create or replace
PROCEDURE CHP_ENCOUNTER_LOAD
AS
** Cursor method to cycle through the DWFILENCOUNTER table and get DWFILENCOUNTER Info for each iRowId.
** Revision History:
** Date Name Description Project
** 07/20/10 ¿-
BEGIN
DECLARE CURSOR source_table IS
SELECT DISTINCT
SI.FIN
FROM
CHP_SURG_INFECTION SI;
-- Declare all Variables ***********
--DECLARE
dblPatient_ID int;
dblOrganization int;
-- Get rows from source table (CHP_SURG_INFECTION) into cursor
--SET NOCOUNT ON
BEGIN
OPEN source_table;
FETCH source_table INTO @FIN
--...bunch more fields here...
--This is where you perform your detailed row-by-row processing.
WHILE @@Fetch_Status = 0
****** Avoid Duplicates Section
-- Select to see if Encounter already exists (FIN exists on the DWFILENCOUNTER table)
SELECT E.FIN
FROM DWFILENCOUNTER E
WHERE E.FIN = @FIN
-- Loop onto next row if already found
IF SQL%NOTFOUND THEN
goto end_loop;
END IF;
******* Lookup Section ************
-- PATIENT - Select Patient from Patient Table (MRN exists on the DWFILPATIENT Table)
SELECT P.Patient_ID into dblPatient_ID
FROM DWFILPATIENT P
WHERE P.MRN = @MRN;
-- Log out Error if Patient Not found and Loop to next Record (don't insert)
IF SQL%NOTFOUND THEN
goto end_loop;
END IF;
-- ORGANIZATION - Select Organization from the DWOrganization table based on name
SELECT O.Organization_Id into dblOrganization_ID
FROM DWDIMORGANIZATION O
WHERE O.ORG_NAME = @FACILITY;
-- Log out Error if Organization Not found and Loop to next Record (don't insert)
IF SQL%NOTFOUND THEN
goto end_loop;
END IF;
**** Insert Rows *********************************
-- Inserting columns in the DWFILENCOUNTER table
INSERT INTO DWFILENCOUNTER (ENCOUNTER_TYPE, FIN, PATIENT_ID, ORGANIZATION_ID )
VALUES (@ENCOUNTER_TYPE, @FIN, dblPatient_ID, dblOrganization_ID)
-- Commit
¿- Get the next row.
FETCH
<<end_loop>>
END
LOOP
CLOSE source_table
DEALLOCATE source_table
RETURN
END CHP_ENCOUNTER_LOAD;Sory for not posting the right code. Here is the code with all vriable included.
create or replace
PROCEDURE CHP_ENCOUNTER_LOAD
AS
** Cursor method to cycle through the DWFILENCOUNTER table and get DWFILENCOUNTER Info for each iRowId.
** Revision History:
** Date Name Description Project
** 07/20/10 ¿-
--SET NOCOUNT ON
-- Declare all Variables ***********
DECLARE
@dblPatient_ID int;
@dblOrganization int;
@FIN VARCHAR2(50 BYTE);
@MRN VARCHAR2(25 BYTE);
@FACILITY VARCHAR2(50 BYTE);
@ENCOUNTER_TYPE VARCHAR2(50 BYTE);
CURSOR source_table FOR
BEGIN
-- Get rows from source table (CHP_SURG_INFECTION) into cursor
SELECT DISTINCT
SI.FIN
SI.ENCNTR_TYPE
FROM
CHP_SURG_INFECTION SI;
OPEN source_table
FETCH source_table INTO
@FIN,
@MRN,
@FACILITY,
@ENCOUNTER_TYPE
--...bunch more fields here...
--This is where you perform your detailed row-by-row processing.
WHILE @@Fetch_Status = 0
BEGIN
--****** Avoid Duplicates Section
-- Select to see if Encounter already exists (FIN exists on the DWFILENCOUNTER table)
SELECT E.FIN
FROM DWFILENCOUNTER E
WHERE E.FIN = @FIN
-- Loop onto next row if already found
IF SQL%NOTFOUND THEN
goto end_loop;
END IF;
--******* Lookup Section ************
-- PATIENT - Select Patient from Patient Table (MRN exists on the DWFILPATIENT Table)
SELECT P.Patient_ID into dblPatient_ID
FROM DWFILPATIENT P
WHERE P.MRN = @MRN;
-- Log out Error if Patient Not found and Loop to next Record (don't insert)
IF SQL%NOTFOUND THEN
goto end_loop;
END IF;
-- ORGANIZATION - Select Organization from the DWOrganization table based on name
SELECT O.Organization_Id into dblOrganization_ID
FROM DWDIMORGANIZATION O
WHERE O.Name = @FACILITY;
-- Log out Error if Organization Not found and Loop to next Record (don't insert)
IF SQL%NOTFOUND THEN
goto end_loop;
END IF;
--**** Insert Rows *********************************
-- Inserting columns in the DWFILENCOUNTER table
INSERT INTO DWFILENCOUNTER (ENCOUNTER_TYPE, FIN, PATIENT_ID, ORGANIZATION_ID )
VALUES (@ENCOUNTER_TYPE, @FIN, @dblPatient_ID, @dblOrganization_ID)
-- Commit
-- Get the next row.
FETCH
<<end_loop>>
END
LOOP
CLOSE source_table
DEALLOCATE source_table
RETURN
END CHP_ENCOUNTER_LOAD; -
Hi,
Can anyone let me know how to close an implicit cursor opened for every individual sql statement? Please note that I am talking about the implicit cursor, not the explicit cursor. I am reaching the maximum open cursor limit and I don't want to increase the open_cursor parameter further as i have already set it a very big value (10000). Rather I would like to know how to close the implicit cursors opened by oracle itself.
Please help.
Thanks in advance.Thanks for your advice. In fact we have already
started re-constructing our coding using explicit
cursor. But the thing is even if the implicit cursors
are kept open till the session ending, it should be
closed when the maximum open_cursor limit is reached
by oracle itself.
The work arroud is well accepted, but I am very eager
to know whether somehow implicit cursor can be closed
or not.You have cursor leaks in your application. Are you closing the cursors? In JDBC (I know you said VB.Net but I don't know much about VB) you call the close method on the Statement objects. May be you are closing most of the cursors but a few are not being closed. In that case, the number of open cursors will slowly creep up to a high number. How often does this error come up? How long before you start seeing it?
Also, take a look at the v$open_cursor view (using your session SID) when you get the error and see if there are certain statements that are repeated a ton of times. This could help you find those statements that are not closed by the application.
Also note, there is a dbms_sql.close_cursor method. Check it out:
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg09dyn.htm#26799
-Raj -
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 -
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?
-
Hi,
I have an application running on NT station versus Oracle 8.0.5 database on NT server.
I'm getting the ORA-01000 error while running a report. This error doesn't appear regulary while running the concerned report. it appears after calling the report several times (closing then opening).
After the error appear everytime I call the report this error appear until the user restart the PC. I did check the report and I'm closing the cursors I opened.
I had the open_cursors parameter in the INIT file set for 400 then I changed to 600 but this didn't change a thing (I restarted my database).
I'm using recursive functions but I'm always closing the cursors before calling the function recursively.
And I also want to notes that the recursive function depending on the data I have won't go more than 2 or 3 levels deeper.
Please confirm it is bug 492362: NT/95/3.1.1 - REPORTS DOES NOT RELEASE OPENED CURSORS. and how to fix it.
THANKS<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Ali DHAINI ([email protected]):
Hi,
I have an application running on NT station versus Oracle 8.0.5 database on NT server.
I'm getting the ORA-01000 error while running a report. This error doesn't appear regulary while running the concerned report. it appears after calling the report several times (closing then opening).
After the error appear everytime I call the report this error appear until the user restart the PC. I did check the report and I'm closing the cursors I opened.
I had the open_cursors parameter in the INIT file set for 400 then I changed to 600 but this didn't change a thing (I restarted my database).
I'm using recursive functions but I'm always closing the cursors before calling the function recursively.
And I also want to notes that the recursive function depending on the data I have won't go more than 2 or 3 levels deeper.
Please confirm it is bug 492362: NT/95/3.1.1 - REPORTS DOES NOT RELEASE OPENED CURSORS. and how to fix it.
THANKS<HR></BLOCKQUOTE>
Hi, i have the same problem. Have you solve this problem? Can you tell me how to fix it?
Thank yoy
null -
Confused about Open Cursors :(
Hi all,
i need some clarification on this issue, i've read throught the documentation and i'm a bit confused.
I'm using 10.1.0.2
select sum(value)
from v$statname sn,
v$sesstat st,
v$session s
where sn.statistic# = st.statistic#
and st.sid = s.sid
and sn.name = 'session cursor cache count'
The result of the above query is 4926, meaning i have 4926 CLOSED cursors in the session cursor cache.
select count(1)
from v$open_cursor
The result of the above query is 16968, meaning i have 16968 cached cursors
So there are two distinct cursor Caches ?
now lets look at other statistic
select sum(value)
from v$statname sn,
v$sesstat st,
v$session s
where sn.statistic# = st.statistic#
and st.sid = s.sid
and sn.name = 'opened cursors current'
this one gives me 12212 , so i have 12212 opened cursors (NOT CACHED , REALLY OPENED CURSORS ...is this correct???)
I suspect that my applications are not closing resultsets (java build application, deployed in oracle application server, database connections in pooled connection) ... so i'm trying to help my developers to find the potencial bug in application.
How can i get the SQL from OPEN cursors ???
V$open_cursor gives me SQL from CLOSED cached cursors ...
Best Regards
Rui MadalenoHi,
>>this one gives me 12212 , so i have 12212 opened cursors (NOT CACHED , REALLY OPENED CURSORS ...is this correct???)
For your instance, yes because you use the sum(value) aggregate function. But I think that the best is get this value per session.
select count(1) from v$open_cursor
v$open_cursor shows cached cursors, not currently open cursors, by session. If you're wondering how many cursors a session has open, don't look in v$open_cursor. It shows the cursors in the session cursor cache for each session, not cursors that are actually open. To monitor open cursors, query v$sesstat where name='opened cursors current'. This will give the number of currently opened cursors, by session:
select a.value, s.username, s.sid, s.serial#
from v$sesstat a, v$statname b, v$session s
where a.statistic# = b.statistic# and s.sid=a.sid
and b.name = 'opened cursors current';
>>I suspect that my applications are not closing resultsets (java build application, deployed in oracle application server, database connections in pooled connection)
In this case, you need to monitor you application. If want, you can use the OEM Database Console and go to [Top Sessions | Session Details] link, or to use this SQL above.
By the way, do you are getting ORA-1000 errors ?
If so, set the OPEN_CURSORS parameter high enough that you never get an ORA-1000 during normal operations.
Cheers -
Hi,
Im using cursor method in my sql query. For two tables, im putting the cursor. Im populating data from two tables into third internal table.
Now, the data from third internal table is inserted into a ztable.
During this entire process, my first cursor will be opened and second cursor will be open and closed till it gets the complete records based on first cursor. data insertion happens into a ztable and finally closing the cursor for the first one.
open cursor dbcur1
open cursor dbcur2
close cursor dbcur2
inserting into ztable
close cursor dbcur1. }
My problem is that a huge time is consumed while inserting the rows into dbtable. Here, im trying to do a batch processing. So for each batch process, my ztable will be inserted with new records.
So, what the best case of reducing the time for processing this activity.
thanks
rohithHi,
The best method i can think of is update the data outside the SQL. Collect data into an internal table. Once all the data is collected, close all the cursors, then INSERT the data into ZTABLE at single shot.
Logic behind this is, it reduces the number of database hits. As we know database operations works on queing principles. So instead of waiting in Q for each INSERT statement, update the data at once and COMMIT.
Hope you got the logic.
Thanks,
Vinod. -
Database selection with invalid cursor !
hi experts,
When execute SAP BW processchar, it occur some system error: (sm21)
Database selection with invalid cursor
The database interface was called by a cursor (in a FETCH or CLOSE
cursor operation) that is not flagged as opened. This can occur if a
COMMIT or ROLLBACK was executed within a SELECT loop (which closes all
opened cursors), followed by another attempt to access the cursor (for
example, the next time the loop is executed).
this error occur when apply bw support package 19.
sap notes 1118584 Solution is: Import Support Package 17 . but my support package is 19.
how can i solve this error?
thanks,
xwu.I am only assuming things, but it might be worth to look closely if you were experiencing an ORA- error during the execution. This could have caused a rollback and thus closed the cursor. Please check the job log, the workprocess trace (dev_wX file) and the system log SM21 and ST22 as well.
Besides that check the oracle alertlog and the usertrace destination.
Best regards, Michael -
Invalid Cursor, Please HEPL ME!!!!!!!
I see the following error:
ERROR at line 1:ORA-01001: invalid cursor
ORA-06512: at "SYS.DBMS_SYS_SQL", line 824ORA-06512: at "SYS.DBMS_SQL", line 32
ORA-06512: at "IWF_ADMIN.SP_ESTADISTICAS", line 38ORA-06512: at line 2
with the following code:
create or replace procedure SP_ESTADISTICASisc_idsite number;c_hora number;
c_dia number;c_fail number:=0;c_incomple number:=0;c_comple number:=0;
c_qnc number:=0;c_wap number:=0;c_fax number:=0;sumbusy number:=0;
c_busy number:=0;sumtime number:=0;sumin number:=0;sumout number:=0;
fechai date;Temp varchar2(20);fechac varchar2(20);--fechac date;
fechaf date;--cursor cursor_est return (idsite tablecall.idsite%typefecha
tablecall.fecha%type, bytein tablecall.bytein%type, typecall
tablecall.typecall%type, num_busych tablecall.num_busych%type, tiempoconec
tablecall.tiempoconec%type);cursor_est tablecall2%ROWTYPE;fdbk INTEGER;
cur INTEGER := DBMS_SQL.OPEN_CURSOR;v_select varchar2(200);begin
select concat(to_char(min(fecha),'dd/mm/yyyy'),' ') into Temp from tablecall2;
for cur_idsite in (select distinct(idsite) as idsite from tablecall2) loop
for c_dia in 0..31 loop fechai:=to_date(Temp,'dd/mm/yyyy');
fechai:=fechai + c_dia; for c_hora in 0..23 loop
-- fechac:=to_date(Temp| |to_char(c_hora,'fm09')| |':00:00');
fechac:=Temp| |to_char(c_hora,'fm09');
-- fechaf:=to_date(Temp| |to_char(c_hora,'fm09')| |':59:59');
v_select:='select idsite,fecha,bytein,typecall,num_busych,tiempoconec
from tablecall2 where idsite ='| |to_char(cur_idsite.idsite,'fm0999')| |' and
to_char(fecha,'| |chr(39)| |'dd/mm/yyyy hh24:mi:ss'| |chr(39)| |') like
'| |chr(39)| |fechac| |'%'| |chr(39);
DBMS_SQL.PARSE(cur,v_select,DBMS_SQL.NATIVE);
DBMS_SQL.DEFINE_COLUMN(cur, 1, 1);
DBMS_SQL.DEFINE_COLUMN(cur, 2, sysdate);
DBMS_SQL.DEFINE_COLUMN(cur, 3, 1); DBMS_SQL.DEFINE_COLUMN(cur, 4, 1);
DBMS_SQL.DEFINE_COLUMN(cur, 5, 1); DBMS_SQL.DEFINE_COLUMN(cur, 6, 1);
fdbk := DBMS_SQL.EXECUTE(cur); LOOP
EXIT WHEN DBMS_SQL.FETCH_ROWS(cur) = 0;
DBMS_SQL.COLUMN_VALUE(cur,1,cursor_est.idsite);
DBMS_SQL.COLUMN_VALUE(cur,2,cursor_est.fecha);
DBMS_SQL.COLUMN_VALUE(cur,3,cursor_est.bytein);
DBMS_SQL.COLUMN_VALUE(cur,4,cursor_est.typecall);
DBMS_SQL.COLUMN_VALUE(cur,5,cursor_est.num_busych);
DBMS_SQL.COLUMN_VALUE(cur,6,cursor_est.tiempoconec);
if cursor_est.bytein=0 then c_fail:=c_fail+1; end if;
if cursor_est.bytein<125 then c_incomple:=c_incomple+1; end if;
if cursor_est.bytein>125 then c_comple:=c_comple+1; end if;
if cursor_est.typecall=2 then c_fax:=c_fax+1; end if;
if cursor_est.typecall=1 then c_qnc:=c_qnc+1; end if;
if cursor_est.typecall=0 then c_wap:=c_wap+1; end if; c_busy:=c_busy+1;
sumbusy:=cursor_est.num_busych + sumbusy;
sumtime:=cursor_est.tiempoconec + sumtime; sumin:=cursor_est.bytein + sumin;
sumout:=cursor_est.byteout + sumout; END LOOP; if c_busy<>0 then
sumbusy:=sumbusy/c_busy; else sumbusy:=0; end if;
execute immediate 'insert into tableest
values('| |to_char(cur_idsite.idsite,'fm0999')| |',
to_date(concat('| |chr(39)| |fechac| |chr(39)| |','| |chr(39)| |':00:00'| |chr(39)| |'),'| |chr(39)| |'dd/mm/yyyy
HH24:mi:ss'| |chr(39)| |'),'| |to_char(c_fail,'fm0999999999')| |','| |to_char(c_incomple,'fm0999999999')| |','| |to_char(c_comple,'fm0999999999')| |','| |to_char(c_wap,'fm0999999999')| |','| |to_char(c_qnc,'fm0999999999')| |','| |to_char(c_fax,'fm0999999999')| |','| |to_char(sumbusy,'fm0999999999')| |','| |to_char(sumtime,'fm0999999999')| |','| |to_char(su min,'fm0999999999')| | ','| |to_char(sumout,'fm0999999999')| |')';
commit; execute immediate 'delete from tablecall2 where
idsite='| |to_char(cur_idsite.idsite,'fm0999')| |' and
to_char(fecha,'| |chr(39)| |'dd/mm/yyyy HH24:mi:ss'| |chr(39)| |') like
'| |chr(39)| |fechac| |'%'| |chr(39);-- commit;
DBMS_SQL.CLOSE_CURSOR (cur); end loop; end loop;end loop;
end;
what is happening it?, how can to resolve it?
Thank by any idea.
nullIt is very difficult to read. However, the previous reply is correct you have closed the cursor inside the loop.
Also, hoping you will take this as a suggestion, I have modified the proc to utilize 8i features and get rid of the DBMS_SQL utility (to much coding) and the CHR(39)
I would have written this in spanish but my ability to write in spanish is shamefull, but
BUENA SUERTE CON TU PROJECTO.
create or replace procedure SP_ESTADISTIC AS
c_dia number;
c_fail number:=0;
c_incomple number:=0;
c_comple number:=0;
c_qnc number:=0;
c_wap number:=0;
c_fax number:=0;
c_busy number:=0;
sumbusy number:=0;
sumtime number:=0;
sumin number:=0;
sumout number:=0;
fechai date;
Temp varchar2(20);
fechac varchar2(20);
TYPE REF_CUR IS REF CURSOR ;
CV REF_CUR ;
v_sql_stmt varchar2(2000);
TYPE CUR_REC IS RECORD
(idsite tablecall.idsite%type,
fecha tablecall.fecha%type,
bytein tablecall.bytein%type,
typecall tablecall.typecall%type,
num_busych tablecall.num_busych%type,
tiempoconec tablecall.tiempoconec%type);
CUR_DATA CUR_REC ;
BEGIN
select concat(to_char(min(fecha),'dd/mm/yyyy'),' ') into Temp from tablecall2;
for cur_idsite in (select distinct(idsite) as idsite from tablecall2) loop
for c_dia in 0..31 loop
fechai:=to_date(Temp,'dd/mm/yyyy');
fechai:=fechai + c_dia;
for c_hora in 0..23 loop
fechac := Temp| |to_char(c_hora,'fm09');
V_SQL_STMT :='select idsite, fecha, bytein, typecall, num_busych, tiempoconec '| |
' from tablecall2 where idsite = '| |
to_char(cur_idsite.idsite, 'fm0999') | |
' and to_char(fecha, ''dd/mm/yyyy hh24:mi:ss'' ) '| |
' like '''| | fechac | | '%'' ';
OPEN CV FOR v_sql_stmt ;
LOOP
FETCH CV INTO CUR_DATA ;
EXIT WHEN CV%NOTFOUND;
if CUR_DATA.bytein=0 then c_fail:=c_fail+1; end if;
if CUR_DATA.bytein<125 then c_incomple:=c_incomple+1; end if;
if CUR_DATA.bytein>125 then c_comple:=c_comple+1; end if;
if CUR_DATA.typecall=2 then c_fax:=c_fax+1; end if;
if CUR_DATA.typecall=1 then c_qnc:=c_qnc+1; end if;
if CUR_DATA.typecall=0 then c_wap:=c_wap+1; end if;
c_busy:=c_busy+1;
sumbusy := CUR_DATA.num_busych + sumbusy;
sumtime := CUR_DATA.tiempoconec + sumtime;
sumin := CUR_DATA.bytein + sumin;
-- sumout:=CUR_DATA.byteout + sumout;
END LOOP;
if c_busy<>0 then
sumbusy:=sumbusy/c_busy;
else
sumbusy:=0;
end if;
v_sql_stmt := 'insert into tableest '| |
' values(:1, :2, :3, :4, :5, :6, '| |
':7, :8, :9, :10, :11, :12 ) ' ;
execute immediate v_sql_stmt using
to_char(CUR_DATA.idsite,'fm0999'),
to_date(fechac| |':00:00', 'dd/mm/yyyyHH24:mi:ss'),
to_char(c_fail, 'fm0999999999'),
to_char(c_incomple,'fm0999999999'),
to_char(c_comple, 'fm0999999999'),
to_char(c_wap, 'fm0999999999'),
to_char(c_qnc, 'fm0999999999'),
to_char(c_fax, 'fm0999999999'),
to_char(sumbusy, 'fm0999999999'),
to_char(sumtime, 'fm0999999999'),
to_char(sumin, 'fm0999999999') ,
to_char(sumout, 'fm0999999999') ;
execute immediate
'delete from tablecall2 where idsite='
| |to_char(cur_idsite.idsite,'fm0999')
| |' and to_char(fecha,''dd/mm/yyyy HH24:mi:ss'' ) '
| |' like '''| | fechac | | '%'' ';
commit;
end loop;
close CV;
end loop;
end loop;
end;
Maybe you are looking for
-
I have an IMAC 27 with a mini display port ( only this). I also have all the adapters ( mini display port to VGA, HDMI...). Since I moved to UAE I like to transmit the signal frm my IMAC ( where I also look German TV on) to my TV. I will do so by usi
-
ADF -- Accessing table column header in java bean called from jsf
Hi everyone, I am calling a common bean function for all columns of a table from jsf inlineStyle, for each call i need to access caller column's headerText in bean. How can i access the same in that common function, i.e. for each column's call to the
-
Generate sample PHP service from db could not set primary key
Hi, Some information about my system: OS :Windows 7 64 bit Computer type: HP Pavilion dv6-3013cl laptop Eclipse 3.5+Flash Builder 4 plugin DB: MySQL 5.0 local server Web Server: Apache 2.2+PHP 5.2.14 Zend Frame work 1.10.1 (installed by Flash Bui
-
How to reinstall Mail and itunes from Time Machine backup
My Mac Pro is running slow and AppleCare have advised to do a clean install of 10.6.6 All my files are backed up and I have done a TM backup. I want to be able to reinstall Apple Mail with all my family email and business email accounts & emails in i
-
Immediately needed the suggestion
Hi all, I am very new in ABAP programming.i want to know does there exists any book from WROX publications(i.e. Professional's edition) if there is kindly let me know. If at all there is any other book (other than SAMS 21 days) kindly let me know. Th