FAQ about OPEN and CLOSE Plsql Cursor in V$OPEN_CURSOR View (文档 ID 235291.1)
2014-01-05 10:32
691 查看
APPLIES TO:
PL/SQL - Version 7.0.13 and laterInformation in this document applies to any platform.
***Checked for relevance on 23-Aug-2013***
PURPOSE
This note provides an example and will address the question about open cursors found within system views after execution has completed.As SYS or SYSTEM - execute the following command (there should be 0 rows)
SELECT oc.user_name, st.sql_text
FROM v$open_cursor oc, v$sqltext st
WHERE oc.address = st.address
AND oc.hash_value = st.hash_value
AND oc.user_name = 'SCOTT'
AND UPPER(st.sql_text) like '%DUAL%'
ORDER BY oc.user_name, st.piece
/
As SCOTT - execute the following:
declare
cursor c_my_curs is
select sysdate the_date
from dual;
begin
for r_my_curs in c_my_curs loop
dbms_output.put_line('The date is
:'||to_char(r_my_curs.the_date,'DD-MON-YYYY')||'.');
end loop;
end;
/
As SYS or SYSTEM - execute the same command as before
SELECT oc.user_name, st.sql_text
FROM v$open_cursor oc, v$sqltext st
WHERE oc.address = st.address
AND oc.hash_value = st.hash_value
AND oc.user_name = 'SCOTT'
AND UPPER(st.sql_text) like '%DUAL%'
ORDER BY oc.user_name, st.piece
/
Results:
USER_NAME SQL_TEXT
--------------- --------------------------------------------------
SCOTT SELECT SYSDATE THE_DATE FROM DUAL
SCOTT from dual; begin for r_my_curs in c_my_curs loop
dbms_outp
QUESTIONS AND ANSWERS
1. Even after the anonymous block is completed the cursors still exist for SCOTT. Does this mean that this cursor is not closed really. Is this a bug?
No this is not a bug . For performance reasons, pl/sql cursors are cached for future reuse. So once used they will be added to LRU list of cursor table which is why they are visible within v$open_cursor.
2. Does this mean the MAX_OPEN_CURSOR limit will be hit sooner than expect?
No. This will not contribute in hitting max_open_cursor . Once max_open_cursor is reached, these "used up" cursor in LRU list will be closed and new requested cursor will be opened.
3. Does that mean the "real open cursor" via v$open_cursor can't be seen? Is there a way to find which cursor is actually opened?
The following query will serve the purpose:
select sum(a.value), b.namefrom v$sesstat a, v$statname b
where a.statistic# = b.statistic#
and b.name = 'opened cursors current'
group by b.name;
|
|
Database Products > Oracle
Database > Application
Development > PL/SQL > PL/SQL > RUN
TIME
|
CURSOR;
OPEN
CURSORS;
V$OPEN_CURSOR;
V$SESSTAT;
V$SQLTEXT;
V$STATNAME
相关文章推荐
- How to Check Whether Oracle Binary/Instance is RAC Enabled and Relink Oracle Binary in RAC (文档 ID 28
- How to Check Whether Oracle Binary/Instance is RAC Enabled and Relink Oracle Binary in RAC (文档 ID 28
- No data in the view dba_hist_undostat (文档 ID 1558157.1)
- Incrementally Updated Backup In 10G and higher (文档 ID 303861.1)
- ALL about SYSDBA and SYSOPER Privileges in Oracle [ID 50507.1]
- ALL about SYSDBA and SYSOPER Privileges in Oracle [ID 50507.1]
- How to Check Whether Oracle Binary/Instance is RAC Enabled and Relink Oracle Binary in RAC (文档 ID 28
- SCRIPT - to Set the 'SESSION_CACHED_CURSORS' and 'OPEN_CURSORS' Parameters(文档 ID 208857.1)
- How to Read Buffer Cache Advisory Section in AWR and Statspack Reports. (文档 ID 754639.1)
- Oracle 'open cursor loop fetch into' and 'for in cursor loop'
- Installing and configuring Csscan in 10g and 11g (Database Character Set Scanner) (文档 ID 745809.1)
- Actual Shipment Dates Are Incorrect In Ar And Material Transaction-Inv. (文档 ID 435322.1)
- Wrong wait events in 11.2 ("cursor: mutex S" instead of "cursor: mutex X") (文档 ID 9591812.8)
- How To Get Log, Trace Files In OA Framework Pages And Concurrent Request Programs (文档 ID 290614.1)
- What is Split Brain in Oracle Clusterware and Real Application Cluster (文档 ID 1425586.1)
- Physical and Logical Block Corruptions. All you wanted to know about it. (文档 ID 840978.1)
- How to Read PGA Memory Advisory Section in AWR and Statspack Reports (文档 ID 786554.1)
- What is Split Brain in Oracle Clusterware and Real Application Cluster (文档 ID 1425586.1)
- 10g Manual Database Creation in Oracle (Single Instance and RAC) (文档 ID 240052.1)
- Oracle PLSQL Demo - 09.Open、Fetch遍历游标[Open, Fetch, Close Record CURSOR]