create or replace procedure updatePro(returndataCur out IPINFO_PACKAGE.curList,curTime in number,endTime in number,dateTime in number,num in number) is authId number;
--声明变量 pro VARCHAR2(32); ipInfoId number; info_ip number; maskLen number; portStart number; portEnd number; direct number; rownumber number; str varchar2(300); cnt int; Cursor groupCur is select auth_id,property from ip_info group by property,auth_id; Cursor curListCur is select id,ip,mask_len,port_start,port_end,dir,property,auth_id from (select t.*,rownum rn from (select id,ip,mask_len,port_start,port_end,dir,property,auth_id from ip_info ip_info where USABLE_TIME_START + dateTime <= endTime and USABLE_TIME_END + dateTime > = endTime and NEXT_USE_TIME < curTime and property=pro and auth_id=authId order by id desc) t where rownum <= num ) s where rn> 0;
begin
--赋值 authId:=0; pro:='m'; ipInfoId:=0; info_ip:=0; maskLen:=0; portStart:=0; portEnd:=0; direct:=0; rownumber:=0; cnt:=0; str:='delete from RETURNDATA'; select count(*) into cnt from all_tables where table_name='RETURNDATA'; --if cnt!=0 then --execute immediate str; --end if; --此处是游标嵌套 open groupCur; loop fetch groupCur into authId,pro; exit when groupCur%notfound; --dbms_output.put_line(authId||pro);
open curListCur; loop
fetch curListCur into ipInfoId,info_ip,maskLen,portStart,portEnd,direct,pro,authId; exit when curListCur%notfound; dbms_output.put_line(ipInfoId); insert into RETURNDATA values(ipInfoId,info_ip,maskLen,portStart,portEnd,direct,pro,authId); update ip_info set last_use_time=curTime,next_use_time=endTime where id=ipInfoId;
end loop; commit;
close curListCur; end loop;
close groupCur; open returndataCur for select * from RETURNDATA; end updatePro;
hibernate里调用存储过程
public List findAllIpInfoList(Long curTime,Long tempNum,Long dateTime,Integer number) { ResultSet rs=null; Session ses = this.getHibernateTemplate().getSessionFactory().openSession(); List ipInfoList=new ArrayList(); try{ Connection cOnn= ses.connection(); conn.setAutoCommit(false); String proc="{Call updatepro(?,?,?,?,?)}"; CallableStatement st = conn.prepareCall(proc); st.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);//输出参数 st.setInt(2,Integer.valueOf(curTime.toString())); st.setInt(3,Integer.valueOf(tempNum.toString())); st.setInt(4,Integer.valueOf(dateTime.toString())); st.setInt(5,number);