zoukankan      html  css  js  c++  java
  • oracle返回多结果集

    kavy 原文 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);
        }
    
    }

     

  • 相关阅读:
    ros 录制
    shell 截取字符串
    Linux 关机
    shell获取字符串长度
    ubuntu14.04 设置开机自启动脚本
    获取本机ip的shell脚本
    shell 杀掉指定进程的服务
    html 绘制矩形轨迹,选中区域
    shell模拟ctrl c停止
    shell 字符串提取数字
  • 原文地址:https://www.cnblogs.com/arxive/p/5959503.html
Copyright © 2011-2022 走看看