class="java" name="code">1.java代码 public static void callProducre() throws Exception { Connection conn = getConn(); String sql = "{call exportExcle(?,?,?,?)}"; CallableStatement statement = conn.prepareCall(sql); // 设置输入参数 statement.setLong(1, 1); statement.setLong(2, 1000); // 设置输出参数 statement.registerOutParameter(3, oracle.jdbc.OracleTypes.CURSOR); statement.registerOutParameter(4, oracle.jdbc.OracleTypes.NUMBER); statement.execute(); // 处理返回结果集 ResultSet rs = (ResultSet)statement.getObject(3); int i=1; while (rs.next()) { System.out.println(rs.getString(1)+":"+rs.getString(2)); i++; } rs.close(); // 输出第4个值 BigDecimal outParam2 = (BigDecimal)statement.getObject(4); System.out.println("输出第4个值:"+outParam2.toString()); statement.close(); conn.close(); }
?2.存储过程
?
create or replace procedure exportExcle(startNum in number,endNum in number,out_cursor out sys_refcursor,totalNum out number) as begin open out_cursor for SELECT * FROM (SELECT tt.*, ROWNUM AS rowno FROM ( select distinct info.tradeno from sc_ipay_pay pay,sc_ipay_prepayment_info info where pay.bill_id=info.billid and pay.amount=29.9 and pay.pay_status=1 and info.user_goods_name like '%药安心%' and to_char(pay.create_time,'yyyy-MM-dd')>='2019-07-07' order by info.tradeno desc ) tt WHERE ROWNUM < endNum) al WHERE al.rowno >= startNum; totalNum:= startNum+endNum; end exportExcle;?
?