oracle 的游标(cursor )的用法。

游标
游标分为显示游标和隐示游标。下面有两个实例然码实践这两个例子
cursor c_name(var_name var_type)
is|as
select ...
from ...<--游标的语法->
where...

游标的属性:
%isopen<--是否打开->
%found
%notfound
%rowcount

用法:
open
fetch
close

create or replace function f_get_ename(p_deptno number)
return number is
 s_sum number ;
 tem number ;
 --显示游标
 cursor c1(p_salary hr.employees.salary%type)
  is 
  select emp.salary
  from hr.employees emp
  where emp.employee_id > p_deptno and emp.employee_id < 205;
  
begin
  s_sum := 0 ;
  --打开游标
  open c1(202);
  loop
    --取数据
    fetch c1 into tem;
    exit when c1%notfound;
    s_sum := s_sum + tem ;
    
  end loop;
  dbms_output.put_line(c1%rowcount) ;
  close c1;
  
  return s_sum ;
end;

--隐式游标
create or replace function f_get_ename(p_deptno number) return number is
  s_sum number;

begin
  s_sum := 0;
  --隐式游标
  for c1 in (select emp.salary
               from hr.employees emp
              where emp.employee_id > p_deptno
                and emp.employee_id < 205) loop
    s_sum := s_sum + c1.salary;
  end loop;

  return s_sum;
end;

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值