Skip to content

Commit 77b3a54

Browse files
committed
A simple procedure to show open cursors
This simple procedure show the amount of cursors you have open and the maximum allowed, also it shows what percentage of the open cursors you are using
1 parent c13ecf2 commit 77b3a54

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

proc_open_cursors.sql

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
REM Script Name : tp_open_cursors.sql
2+
REM Author : Craig Richards
3+
REM Created : 27 September 2013
4+
REM Last Modified :
5+
REM Version : 1.0
6+
REM
7+
REM Modifications :
8+
REM
9+
REM Description : Shows the open cursors and the maximum number of cursors
10+
11+
CREATE OR REPLACE PROCEDURE tp_open_cursors
12+
AS
13+
14+
-- Variable Declaration
15+
16+
lv_highest sys.v$sesstat.value%TYPE;
17+
lv_max sys.v$parameter.value%TYPE;
18+
lv_percentage NUMBER;
19+
20+
-- Create the cursors
21+
22+
CURSOR c_open_cursor IS
23+
SELECT MAX(a.value) AS highest_open_cursor, p.value AS max_open_cursor
24+
FROM v$sesstat a, v$statname b, v$parameter p
25+
WHERE a.statistic# = b.statistic#
26+
AND b.name = 'opened cursors current' AND p.name= 'open_cursors'
27+
GROUP BY p.value;
28+
29+
-- Output the Information
30+
31+
BEGIN
32+
DBMS_OUTPUT.PUT_LINE(CHR(10)||'Open ' || CHR(9) || 'Max Cursors');
33+
DBMS_OUTPUT.PUT_LINE('==== ' || CHR(9) || '===========');
34+
OPEN c_open_cursor;
35+
LOOP
36+
FETCH c_open_cursor into lv_highest,lv_max;
37+
EXIT WHEN c_open_cursor%NOTFOUND;
38+
DBMS_OUTPUT.PUT_LINE(lv_highest||CHR(9)||lv_max);
39+
END LOOP;
40+
CLOSE c_open_cursor;
41+
lv_percentage := (lv_highest / lv_max *100);
42+
DBMS_OUTPUT.PUT_LINE (CHR(10) || 'You are using ' || TRUNC(lv_percentage,2) || '% of the open_cursors parameter');
43+
END tp_open_cursors;
44+
/

0 commit comments

Comments
 (0)