hibernate调用oracle的带有返回值的存储过程

来源:互联网 发布:函数式编程思想 编辑:程序博客网 时间:2024/05/18 12:05

存储过程如下:

create or replace
procedure QQT_buConsumerAdds2(consums out number) AUTHID CURRENT_USER as
v_consums number;
v_allConsums number;
v_buid qqt_businessuser.businessuserid%type;
v_buConsum user_objects.object_name%type;
v_conusm_sql varchar2(1000);
begin
      v_allConsums:=0;
      declare
      cursor CONSUMERINFOS is
       select regexp_replace(object_name,'[a-z|A-Z|_]','') buId,object_name buTableName
        from user_objects where   object_name like 'QQT_CONSUMERINFO_SHOP%'  AND object_name<>'QQT_CONSUMERINFO_SHOP'
        AND object_type='TABLE'  and exists (
        select businessuserid from qqt_businessuser where businessuserid=regexp_replace(object_name,'[a-z|A-Z|_]','')
        );
      begin
        open CONSUMERINFOS ; 
           loop
              fetch CONSUMERINFOS into v_buid,v_buConsum;    
                 v_conusm_sql:='select count(*) from '||v_buConsum||' qcs,qqt_cardtype qc where trunc(qcs.DATINSERT)=trunc(sysdate-1) and qcs.cardtypeid=qc.cardtypeid and qc.type=0';                
                 execute immediate v_conusm_sql  into v_consums;
                 v_allConsums:=v_allConsums+v_consums; 
                 if(v_consums>0) then
                    dbms_output.put_line('会员增加了:'||v_consums||'v_buConsum='||v_buConsum);
                 end if;
                 exit when CONSUMERINFOS%notfound;
            end loop;   
        close CONSUMERINFOS; 
      end;
        dbms_output.put_line('会员昨天的增加了:'||v_allConsums);
        consums:=v_allConsums;
      Exception
       When others then  dbms_output.put_line('v_buConsum:='||v_buConsum);
   
end ;

java service的方法如下:

@SuppressWarnings("unchecked")
 @Override
 public Integer yesAddConsums() {
  // TODO Auto-generated method stub
  return (Integer)this.getHibernateTemplate().execute(new HibernateCallback() {
   
   public Integer doInHibernate(Session session) throws HibernateException,
     SQLException {
    // TODO Auto-generated method stub
     @SuppressWarnings("deprecation")
    CallableStatement  statement = session.connection().prepareCall( 
                "call QQT_buConsumerAdds2(?)"); 
     statement.registerOutParameter(1, OracleTypes.NUMBER); 
     statement.execute();
     System.out.println("yesAddConsums"+statement.getString(1));
     String keycode = statement.getString(1); 
    return   Integer.parseInt(keycode);
   }
  });
 }

遇到的问题只要的是  statement.registerOutParameter(1, OracleTypes.NUMBER); 中用OracleTypes.NUMBER。
原创粉丝点击