zoukankan      html  css  js  c++  java
  • Oracle ref 游标(转)

    ref游标和普通游标(自定义游标)最大的区别是游标的结果集在什么地获取。

    普通游标在声明的时候,获得结果集,例子 cursor v_cur is select * from t_test;

    而ref游标在打开的时候,获得结果集,

    例子:open infolist for select bi.* from bi_customer cf;

    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--包  
     
      
      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; 

  • 相关阅读:
    在Oracle中添加用户 赋权 修改暗码 解锁
    Ubuntu Linux 8.04 Vsftp 假造用户设置
    用一个实例讲解DB2数据库游标轮回的成果
    解说Oracle数据库自动增长列的完成过程
    MSN登录错误“80072efd”解决办法
    再学 GDI+[61]: 路径画刷(1) SetCenterColor、SetSurroundColors
    WinAPI: 测试 BitBlt
    两个 CopyRect
    再学 GDI+[58]: 路径 保存与读取路径数据
    再学 GDI+[62]: 路径画刷(2) SetCenterPoint、GetCenterPoint
  • 原文地址:https://www.cnblogs.com/YangBinChina/p/2627714.html
Copyright © 2011-2022 走看看