光标的属性和光标数的限制

/*
1.光标的属性
%found :当前光标还有数组
%notfound :当前光标没有数据了(判断最后一次fetch的结果,如果之前没有fetch,返回NULL,这时不会退出下面的循环语句(exit when cur%notfound),为了安全起见,应该再加上 or cur%notfound is null)
%isopen : 判断光标是否打开
%rowcount: 影响的行数

  1. 光标数的限制:默认情况下, 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;
/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值