`
wenjie12201
  • 浏览: 148326 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论
  • luoxun11: 其实这个问题的本质是用##包围变量的时候ibatis会采用St ...
    iBATIS #和$

plsql调用带输出参数的存储过程

 
阅读更多

--v_returncode是out参数
declare
  v_out number;
begin
proc_GetAwardPrize(v_productid => 364,v_userid => 3,v_awardtype => 1,v_returncode =>  v_out);
  DBMS_OUTPUT.PUT_LINE('v_out='||v_out);
end;

以下是存储过程:
create or replace procedure proc_GetAwardPrize(v_productid number,v_userid number,v_awardtype number,v_returncode out number) is
v_awardid prd_award.awardid%type;  
v_awardlevel pub_typeinfo.name%type;
v_cost prd_award.awardcost%type;
v_name prd_award.awardname%type;  
v_flag prd_award.flag%type;
v_temp pub_typeinfo.name%type;
cursor award_cursor is
   select awardid,awardcost,awardname,flag from prd_award where status=1 and piid=v_productid and awardtype=v_awardtype;
begin
   open award_cursor;
   loop
     fetch award_cursor into v_awardid,v_cost,v_name,v_flag;
     exit when award_cursor%notfound;
     v_awardlevel := '';
     if v_flag=1 then
        select '获得'||pt.name||': '||pa.awardname into v_awardlevel from pub_typeinfo pt,prd_award pa where pa.awardtype=pt.code and pa.awardtype=v_awardtype and pt.remark='prizeLevel' and pa.awardid=v_awardid;
        insert into prd_useraward (uaid,awardid,userid,piid,status,awardlevel,wintime) values(SEQ_PRD_USERAWARD.Nextval,v_awardid,v_userid,v_productid,0,v_awardlevel,sysdate);
     else
        select '获得'||pt.name||' ' into v_awardlevel from pub_typeinfo pt,prd_award pa where pa.awardtype=pt.code and pa.awardtype=v_awardtype and pt.remark='prizeLevel' and pa.awardid=v_awardid;
        select name into v_temp from pub_typeinfo where remark='attribute' and code=TO_NUMBER(v_name);
        update usr_userinfoext set EXTVALUENUM=EXTVALUENUM+v_cost where EXTCODE=TO_NUMBER(v_name) and userid=v_userid;
        insert into prd_useraward (uaid,awardid,userid,piid,status,awardlevel,wintime) values(SEQ_PRD_USERAWARD.Nextval,v_awardid,v_userid,v_productid,1,v_awardlevel||v_temp||v_cost,sysdate);
     end if;      
   end loop;
   v_returncode :=0;
   EXCEPTION
      WHEN OTHERS THEN
      rollback;
      DBMS_OUTPUT.PUT_LINE('执行得到奖励过程发生错误!');
      v_returncode :=1;
   close award_cursor;
end proc_GetAwardPrize;

ibaits调用方法:
public int GetAwardPrize(Long piid, Long userid, Integer awardtype) {
  // TODO Auto-generated method stub
  int returncode = 0;
  try{
   Map params = new HashMap();
   params.put("productid", piid);
   params.put("userid", userid);
   params.put("awardtype", awardtype);
   getSqlMapClientTemplate().queryForObject("getAwardPrize", params);
   returncode = (Integer) params.get("returncode");
  }catch(Exception e){
   e.printStackTrace();
   returncode = 1;
  }
  return returncode;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics