PL/SQL学习笔记五

游标是从数据库中提取出来的数据,以临时表的形式存放在内存中,在游标中有一个数据指针,在初始状态下指向首记录, 利用fetch语句移动该指针,从而对游标中的数据进行各种操作。

 

1.定义游标

cursor 游标名 is select语句;

 

2.打开游标

open 游标名;

 

3.提取游标数据

fetch 游标名 into 变量名1, 变量名2, ....;

fetch 游标名 into 记录型变量名;

 

4.关闭游标

close 游标名;

 

5.游标的属性

%isopen

该属性标识游标是否打开,如果没有打开游标就使用fetch语句将提示错误。

 

%isfound

该属性标识一个fetch语句是否有值,有值返回true,否则返回false。

 

%notfound

该属性与%isfound相反。

 

%rowcount

该属性用于获取游标的数据行数。

 

示例:

set serveroutput on

declare

  tempsal scott.emp.sal%type;

  cursor mycursor is

    select * from scott.emp

    where sal>tempsal;

  cursorrecord mycursor%rowtype;

begin

  tempsal:=800;

  open mycursor;

  if mycursor%isopen then

    fetch mycursor into cursorrecord;

    dbms_output.put_line(to_char(cursorrecord.deptno));

    dbms_output.put_line(to_char(mycursor%rowcount));

  else

    dbms_output.put_line('游标还未打开');

  end if;

end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值