/*
1.光标的属性
%found :当前光标还有数组
%notfound :当前光标没有数据了(判断最后一次fetch的结果,如果之前没有fetch,返回NULL,这时不会退出下面的循环语句(exit when cur%notfound),为了安全起见,应该再加上 or cur%notfound is null)
%isopen : 判断光标是否打开
%rowcount: 影响的行数
- 光标数的限制:默认情况下, oracle数据库只允许在同一个会话中,打开300个光标
SQL> show parameter cursor (模糊查询 cursor)
NAME TYPE VALUE
------------------------------------ ----------- --------------
cursor_sharing string EXACT
cursor_space_for_time boolean FALSE
open_cursors integer 300
session_cached_cursors integer 50
修改光标数的限制:
alter system set open_cursors=400 scope=both
scope 的取值: both (包括当前实例和参数文件),menory(只更改当前实例,不更改参数文件),spfile(只更改参数文件,不更改当前实例.数据库需要重启)
*/
--打开显示开关
set serveroutput on
declare
--定义光标
cursor cur is select * from cfg_distributor;
prow cfg_distributor%rowtype;
begin
--打开光标
open cur;
if cur%isopen then
dbms_output.put_line('光标已经打开');
else
dbms_output.put_line('光标没有打开');
end if;
--关闭光标
close cur;
end;
/
declare
--定义光标
cursor cur is select * from cfg_distributor ;
prow cfg_distributor%rowtype;
begin
--打开光标
open cur;
loop
--取出一条记录
fetch cur into prow;
exit when cur%notfound;
--打印rowcount的值
dbms_output.put_line('当前rowcount为'||cur%rowcount);
end loop;
--关闭光标
close cur;
end;
/