java调用存储过程out参数为游标

create or replace package pkg_sxxtj as
 type sxxtj_out_values is ref cursor;
 procedure auditing_result(startDate in date,endDate in date,out_list out sxxtj_out_values);
end pkg_sxxtj;
****************************************************************************

 

create or replace package body pkg_sxxtj as
procedure auditing_result(startDate in date,endDate in date,out_list out sxxtj_out_values)
is
sqlStr varchar2(900);
begin
     if startDate is null and endDate is null then
     open out_list for
        select * from (select t.node_id as node_id, count(t.node_id) as total_count,
               sum(case when t.operate_status='0' then 1 else 0 end) as sh_count,
               sum(case when t.operate_status='1' then 1 else 0 end) as sy_count,
               sum(case when t.over_time > t.operate_date then 1 else 0 end) as js_count,
               sum(case when t.over_time < t.operate_date then 1 else 0 end) as cs_count
          from card_business_node t where t.node_id not in (0007, 0011) group by t.node_id
        union
        select s.sh_node_id as node_id, count(s.sh_node_id) as total_count,
               sum(case when s.operate_status='0' then 1 else 0 end) as sh_count,
               sum(case when s.operate_status='1' then 1 else 0 end) as sy_count,
               sum(case when s.over_time > s.operate_date then 1 else 0 end) as js_count,
               sum(case when s.over_time < s.operate_date then 1 else 0 end) as cs_count from card_business_sh_node s group by s.sh_node_id)  res;

  end if;
     end auditing_result;
     end pkg_sxxtj;

*************************************************************************

// 下面是java 源码,从oracle存储过程读取记录集
// 注意一定要用oracle的jdbc API ( 可以从oracle网站下载 )
public void test(){
  //Session session=getSession();
  Connection con=null;
  OracleCallableStatement cs=null;
  OracleResultSet rs=null;
  SimpleDateFormat sdf=new SimpleDateFormat("",Locale.SIMPLIFIED_CHINESE);
  sdf.applyPattern("yyyy年MM月dd日 HH时mm分ss秒");
  java.sql.Date sd=null;
   con=getSession().connection();
   try {
    cs=(OracleCallableStatement) con.prepareCall("{call pkg_sxxtj.auditing_result(?,?,?)}");
    cs.setDate(1, sd);
    cs.setDate(2, sd);
    cs.registerOutParameter(3,OracleTypes.CURSOR);
    //cs.registerOutParameter(3,java.sql.Types.OTHER);
    cs.execute();
    rs=(OracleResultSet) cs.getCursor(3);
    while(rs.next()){
     log.info("===================环节号:"+String.valueOf(rs.getString(1)));
     log.info("||统计数:"+String.valueOf(rs.getInt(2)));
    }
    
 
    
   } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }finally{
      try {
       if(cs!=null){
       cs.close();
       }
      } catch (SQLException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
      try {
       if(con!=null){
        con.close();
        }
      } catch (SQLException e) {
       // TODO: handle exception
       e.printStackTrace();
      }
   }
 }

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值