Oracle ref 游标

1.获得结果集

 

 

declare
  type refcursor is ref cursor; --ref游标类型
 infolist     refcursor; --集合
  customer     bi_customer%rowtype; --行
  customercode bi_customer.customercode%type;--字段
  customername bi_customer.corporation%type;
begin
  open infolist for
    select bi.* from bi_customer cf; --全部
  loop
    fetch infolist
      into customer;
    exit when infolist%notfound;
    dbms_output.put_line('客户编号为;:'||''||customer.customercode||',   地址为:'||customer.address );
  end loop;
  close infolist;
end;                 

2 过程限定结果集,带返回记录数

create or replace package ord is--包

  -- Author  : SIMON
  -- Created : 2009-7-6 9:27:40
  -- Purpose : 

  type ref_type is ref cursor;

  procedure p_order(firstindex in number,--开始下标
                    lastindex  in number,--结束下标
                    recordnum  out number,--记录数
                    infolist   out ref_type--结果集
);
end ord;

create or replace package body ord is

  procedure p_order(firstindex in number,
                    lastindex  in number,
                    recordnum  out number,
                    infolist   out ref_type) as
    sql_tempstr  varchar2(400);
    sql_countstr varchar(500);
  begin
    sql_tempstr := 'select *
        from (select rownum num, o.* from orders o) s
       where 1>0';
    if (firstindex is not null and lastindex is not null) then
      sql_tempstr := sql_tempstr || 'and num between ' || firstindex ||
                     ' and
                     ' || lastindex;
    end if;
    sql_countstr := ' select count(*) from(' || (sql_tempstr) || ') ';
    dbms_output.put_line(sql_tempstr);
    dbms_output.put_line(sql_countstr);
    open infolist for sql_tempstr;
    Execute Immediate sql_countstr
      into recordnum;
  end p_order;

end ord;

 r

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值