In this Document
Purpose
Scope and Application
Monitoring Open Cursors & Troubleshooting ORA-1000 Errors
References
This section covers the monitoring and managing of the open cursors.
The number of open cursors can limit operation in PL/SQL procedures and SQL*Plus sessions. While the parameter open_cursors sets the limit, programming issues can cause the following error:
ORA-1000 maximum open cursors exceeded
Three important values are the following:
These values are similar, but differ in their accounting of Dynamic Cursors.
Note: Dynamic cursors are those opened using DBMS_SQL.OPEN_CURSOR().
The means to compute those values are as follows:
View v$open_cursor
The following SQL calculates the:
implicit cursors used + distinct explicit cursors opened + dynamic cursors PARSED and NOT CLOSED.
It also:
- Accumulates dynamic cursors PARSED and NOT CLOSED over a session
- Available to system/manager
- Includes the text of open cursors - helpful for debugging
- Since this view does not track unparsed (but opened) dynamic cursors,
the count(*) may not show all cursors that count against open_cursors.
View v$sysstat
The following SQL calculates the:
implicit cursors used + distinct explicit cursors opened + dynamic cursors OPENED.
It also:
- Accumulates dynamic cursors OPENED and NOT CLOSED over a session
- Available to system/manager
- Since this view does track unparsed (but opened) dynamic cursors, the statistic#3 shows all cursors that count against open_cursors.
init.ora parameter open_cursors
This parameter equal:
implicit cursors used + distinct explicit cursors opened + dynamic cursors OPENED.
It also:
- Accumulates dynamic cursors OPENED and NOT CLOSED over a session
ORA-1000
The following are several items to check when encountering ORA-1000 in PL/SQL:
1. Be sure that all dbms_sql cursors opened at DECLARE time are closed. Every unclosed OPEN counts against open_cursors. The number of open cursors can be determined as follows in SQL*Plus:
2. Be aware that v$open_cursor only tracks the CUMULATIVE number of implicit + distinct explicit cursors in the procedure PLUS unclosed dynamic cursors that have been PARSED in the session.
Note: It does not include any dynamic cursors that were opened but not parsed.
The text of the parsed, open cursors can be determined as follows in SQL*Plus:
3. Dynamic cursors persist from run-to-run in a session, but are not closeable after a procedure has completed. This can accumulate and error-out with open_cursors after a number of runs. They will not
appear in v$open_cursors after a session.
The following are two code snippets that can help diagnose ORA-1000. Text lines are shown for each cursor.
-- snippet 1
set serveroutput on
declare
cursor opencur is select * from v$open_cursor;
ccount number;
begin
select count(*) into ccount from v$open_cursor;
dbms_output.put_line(' Num cursors open is '||ccount);
ccount := 0;
-- get text of open/parsed cursors
for vcur in opencur loop
ccount := ccount + 1;
dbms_output.put_line(' Cursor #'||ccount);
dbms_output.put_line(' text: '|| vcur.sql_text);
end loop;
end;
/
Num cursors open is 144
Cursor #1
text: select priority from resource_mapping_priority$ where attrib
Cursor #2
text: select i.obj#,i.ts#,i.file#,i.block#,i.intcols,i.type#,i.fla
Cursor #3
text: select value, consumer_group from resource_group_mapping$ wh
:
:
:
Cursor #142
text: select col#,intcol#,reftyp,stabid,expctoid from refcon$ wher
Cursor #143
text: table_1_ff_14f_0_0_0
Cursor #144
text: SELECT COUNT(*) FROM V$OPEN_CURSOR
Cursor #145
text: select /*+ index(idl_sb4$ i_idl_sb41) +*/ piece#,length,piec
PL/SQL procedure successfully completed.
-- snippet 2
NOTE:1012266.6 - Overview of ORA-1000 Maximum Number of Cursors Exceeded
The following SQL queries are useful in diagnosing the ORA-01000 problem. To execute these queries, you need to logged into the database as an administrator or your DB Admin grants you permissions to select from those v$ views.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/11134237/viewspace-684420/ ,如需转载,请注明出处,否则将追究法律责任。