java ibatis调动oracle传入clob参数的存储过程

本文介绍了一种在Java程序中通过ibatis框架调用Oracle存储过程的方法,特别是当存储过程涉及到CLOB参数时的解决方案。通过将CLOB参数预先存入临时表再由存储过程读取的方式,成功实现了功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我试了几个,得出结论:

java程序,无法直接用ibatis调动oracle传入clob参数的存储过程,而只能将clob参数插入数据库表的字段,插入时直接传入String参数就可以,所以,标题应该这么解决:

1.将clob字段先插入数据库中建有clob字段的临时表

2.存储过程中从表中将clob字段取出使用。

我的代码如下:

oracle数据库建表:

create table t_temp_sendbatchfj(
rightcodes clob,
errorcodes clob,
clientid varchar2(20),
mainid varchar2(20));

java代码(其中erroecodes和rightcodes都是要使用的clob字段,从ibatis传入时直接传String类型即可传入oracle的clob字段):

Map p_pro = new HashMap();
			//由于java无法调用in_clob的存储过程,所以先将clob插入表,然后再从表中取出clob供存储过程用
			p_pro.put("errorcodes", errorcodes.toString());
			p_pro.put("rightcodes", rightcodes.toString());
			p_pro.put("clientid", (String)p.get("clientid"));
			p_pro.put("mainid", (String)p.get("mainid"));
			dao.getSqlMapClientTemplate().insert("sendmsg.sendbatchfj_insert", p_pro);
			//调用分表的存储过程
			dao.getSqlMapClientTemplate().update("sendmsg.proc_p_sendbatch1", p_pro);

<!-- 批量物流版分表存储过程:p_sendbatch1
	drop public synonym  pk_busi_core;
	Grant execute on  pk_busi_core to yxclient;
	create public synonym pk_busi_core for ydsoft_test.pk_busi_core
	-->
	<insert id="sendbatchfj_insert" parameterClass="java.util.Map">
		insert into t_temp_sendbatchfj (
			rightcodes,errorcodes,clientid,mainid
		) 
		values (
			#rightcodes#,#errorcodes#,#clientid#,#mainid#
		)
	</insert>
    <update id="proc_p_sendbatch1" parameterClass="java.util.Map" >
       { call p_sendbatch1(#clientid#,#mainid#)}
     </update>

存储过程中clob的使用:

create or replace procedure p_sendbatch1(in_clientid in varchar2,in_mainid in varchar2)
--clientid在反条数时用,mainid在查正确错误id时用
as 
in_right clob;
in_error clob;
begin 
  select errorcodes,rightcodes into in_error,in_right from t_temp_sendbatchfj where mainid=in_mainid;

....

 --删除clob
    delete from t_temp_sendbatchfj where mainid=in_mainid;
end;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值