您的位置:首页 > 数据库 > SQL

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 later

Information 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.name

from v$sesstat a, v$statname b

where a.statistic# = b.statistic#

and b.name = 'opened cursors current'

group by b.name;


 



 
 


相关内容

  
 
 


产品

  
 
Oracle
Database Products > Oracle
Database > Application
Development > PL/SQL > PL/SQL > RUN
TIME

 


关键字

  
 

CURSOR;

OPEN
CURSORS;

V$OPEN_CURSOR;

V$SESSTAT;

V$SQLTEXT;

V$STATNAME
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐