a cursor attribute
%found: the cursor found the record is true
%notfound: true if the cursor did not find the record
%isopen: determine whether the cursor is open
%rowcount: The number of rows affected
Two examples
Demonstrate the %isopen property
1. Code
set serveroutput on
declare
--定义光标
cursor cemp isselect empno,empjob from emp;
pempno emp.empno%type;
pjob emp.empjob%type;
begin
open cemp;
if cemp%isopen then
dbms_output.put_line('光标已经打开');
else
dbms_output.put_line('光标没有打开');
endif;
close cemp;
end;
/
2. Running results
Cursor is already open
PL/SQL procedure completed successfully.
Demonstration
of the %rowcount property
1. Code
set serveroutput on
declare
--定义光标
cursor cemp isselect empno,empjob from emp;
pempno emp.empno%type;
pjob emp.empjob%type;
begin
open cemp;
loop
--取出一条记录
fetch cemp into pempno,pjob;
exitwhen cemp%notfound;
--打印rowcount的值
DBMS_OUTPUT.PUT_LINE('rowcount:'||cemp%rowcount);
end loop;
close cemp;
end;
/
2. Running results
rowcount:1
rowcount:2
rowcount:3
rowcount:4
rowcount:5
rowcount:6
rowcount:7
rowcount:8
rowcount:9
rowcount:10
rowcount:11
rowcount:12
rowcount:13
rowcount:14
Three-cursor limit
1. Concept
By default, the oracle database only allows 300 cursors to be opened in the same session
Cursor limit viewing method:
SQL> show parameter cursor
NAME TYPE VALUE
-----------------------------------------------------------------------------
cursor_sharing string EXACT
cursor_space_for_time boolean FALSE
open_cursors integer 300
session_cached_cursors integer 50
Modify the limit on the number of cursors:
alter system set open_cursors = 400 scope=both;
the value of scope
both: Change the current instance and also change the parameter file.
memory: Only the current instance is changed, not the parameter file.
spfile: Only the parameter file is changed, but the current instance is not changed. The database needs to be restarted.
2. Examples
SQL> alter system set open_cursors =400 scope=both;
系统已更改。
SQL> show parameter cursor
NAME TYPE VALUE
-----------------------------------------------------------------------------
cursor_sharing string EXACT
cursor_space_for_time boolean FALSE
open_cursors integer 400
session_cached_cursors integer 50