oracle返回多结果集

Oracle存储过程:
create or replace procedure P_Sel_TopCount2(in_top    in number,
                                           out_count out number,
                                           cur_out_1 out sys_refcursor,
                                           cur_out_2 out sys_refcursor) is
--查询指定记录条数的数据,并返回总共记录数,返回多个数据集
begin
SELECT COUNT(*) into out_count FROM userinfo;
open cur_out_1 for
    SELECT * FROM userinfo where id < in_top;
open cur_out_2 for
    SELECT * FROM userinfo where id < 5;
end P_Sel_TopCount2;

 

Java调用

简单地写一个Java Class.

public void openCursor(){
    Connection conn = null;
    ResultSet rs = null;
    CallableStatement stmt = null;
    String sql = “{? = call PKG_HOTLINE.getHotline()}“;
    try{
       conn = getConnection();
       stmt = conn.prepareCall(sql);
       stmt.registerOutParameter(1,OracleTypes.CURSOR);
       stmt.registerOutParameter(2,OracleTypes.CURSOR);
       stmt.execute();
       rs = ((OracleCallableStatement)stmt).getCursor(1);
       while(rs.next()){
           String country = rs.getString(1);
           String pno = rs.getString(2);
           System.out.println(“country:“+country+“|pno:”+pno);
       }
      rs = ((OracleCallableStatement)stmt).getCursor(2);
       while(rs.next()){
           String country = rs.getString(1);
           String pno = rs.getString(2);
           System.out.println(“country:“+country+“|pno:”+pno);
       }
    }
    catch(Exception ex)
    {
        ex.printStackTrace();
    }
    finally
    {
        closeConnection(conn,rs,stmt);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值