oracle游标(返回多条数据)分页

create or replace package test_mypackage1 as
--声明类型,并引用游标
type cursorType is  ref cursor;
  --声明存储过程,两个输入参数,一个输出参数,输出游标类型数据
  procedure prcGetGlobalAddress(pos1 integer,
                                --分页查询的下限
                                pos2 integer,
                                --分页查询的上限
                                cur in out test_mypackage1.cursorType
                                --输出参数,数据类型为引用游标的类型
                                );
end test_mypackage1;

create or replace package body test_mypackage1 as
--定义存储过程
       procedure prcGetGlobalAddress(pos1 integer, pos2 integer, cur in out test_mypackage1.cursorType) as
       begin
--返回得到分页查询结果集的游标句柄
       open cur for select * from(select a.*, rownum rn from(select * from mes_appointment_machine) a where rownum <= pos2) where rn > = pos1;
       end prcGetGlobalAddress;
end test_mypackage1;

// 调用oracle的存储过程 ---> 查询数据得到游标
 public static void invokeProcedureResutl() {
  Connection conn = null;
  CallableStatement callableStatement = null;
  try {
   conn = DBUtils.getConnection();
   // 第一步:获得CallableStatemen的实例;
   callableStatement = conn
     .prepareCall("{call test_mypackage1.prcGetGlobalAddress(?,?,?)}");

   // 第二步:为输出参数注册数据类型,为输入参数赋值;
   callableStatement.registerOutParameter(3,
     oracle.jdbc.driver.OracleTypes.CURSOR);

   callableStatement.setInt(1, 1);
   callableStatement.setInt(2, 50);
   // 第三步:执行存贮过程和获得返回值
   callableStatement.execute();
   ResultSet result = (ResultSet) callableStatement.getObject(3);
   if (result != null) {
    while (result.next()) {
     System.out.println(result.getString(1) + "---"
       + result.getString(2) + "---" + result.getString(3)
       + "---" + result.getString(4) + "---"
       + result.getString(5) + "---" + result.getString(6)
       + "---" + result.getString(7) + "---"
       + result.getString(8));
    }
   }
   // System.out.println(result);
  } catch (Exception e) {
   e.printStackTrace();
  }
 }

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值