码迷,mamicode.com
首页 > 数据库 > 详细

ibatis3.0调用Oracle的存储过程

时间:2015-04-02 18:51:14      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

直接上源码

一,oracle储存过程。 

create or replace procedure proc_get_th(
i_hth in varchar2,
o_ret out sys_refcursor
)
is
begin
for v_rec in (select ggd_id,th from gms_ggd_zt where hth=i_hth)
loop
insert into tmp_gms_plan_th(ggd_id,th)
select ggd_id,th from table(f_get_th(v_rec.ggd_id,v_rec.th));
end loop;

open o_ret for
select gpt.ggd_id,gpt.th
from tmp_gms_plan_th gpt
where (gpt.ggd_id,gpt.th) not in
(select ggd_id,th from gms_plans);

delete from tmp_gms_plan_th;
commit;

end;

二,ibatis的xml配置。

 

<resultMap id="ResultGmsTH" type="com.pisx.app.gms.entity.GmsPlans" >
<result column="GGD_ID" property="ggdId" jdbcType="VARCHAR" />
<result column="th" property="th" jdbcType="VARCHAR" />
</resultMap>

<!--第一种写法 查询语句 --> 缺点:参数值的顺序一定要和数据库对应
<select id="queryPlansByHthProc" parameterType="java.util.Map" statementType="CALLABLE">

<![CDATA[

call proc_get_th(#{hth,mode=IN,jdbcType=VARCHAR},
#{result,mode=OUT,jdbcType=CURSOR,javaType=java.sql.ResultSet,resultMap=ResultGmsTH}
)

]]>

</select>

<!--第二种写法 查询语句 --> 

<select id="queryPlansByHthProc" parameterType="java.util.Map" statementType="CALLABLE">

<![CDATA[

call proc_get_th( hth => #{hth,mode=IN,jdbcType=VARCHAR},
 result => #{result,mode=OUT,jdbcType=CURSOR,javaType=java.sql.ResultSet,resultMap=ResultGmsTH}
)

]]>

</select>

 

三,获取返回值。

 gmsPlansSerivice.queryPlansByHthProc(map);

(List<GmsPlans>) map.get("result");

说明:返回值会自动装在你的参数里面。

 

ibatis3.0调用Oracle的存储过程

标签:

原文地址:http://www.cnblogs.com/luocheng/p/4387696.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!