开发中,在有clob的批量插入过程中,用Java中的String类型通过mybatis进行插入,并且同时有序列。当前试下来,只有一种方式。就只有begin end有用。
begin
XXX;
XXX;
end;
接下来讲下详细过程。
Mybatis
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.test.OracleTableMapper">
<resultMap id="BaseResultMap" type="com.test.OracleTable">
<result column="id" jdbcType="BIGINT" property="id"/>
<result column="code" jdbcType="VARCHAR" property="code"/>
<result column="data" jdbcType="CLOB" property="data"/>
</resultMap>
<insert id="batchInsert" parameterType="map">
begin
<foreach collection="list" item="item" separator=" ; ">
insert into oracle_table (id, code, data)
values
(
oracle_table_seq.nextval, #{item.code,jdbcType=VARCHAR}, #{item.data,jdbcType=CLOB}
)
</foreach>
;end;
</insert>
</mapper>
实体类
@Data
public class OracleTable{
/**
* 主键
*/
private Long id;
/**
* 编码
*/
private String code;
/**
* clob数据
*/
private String data;
}
表
create table oracle_table(
id number primary key not null,
code varchar2(32),
data clob
)
序列
create sequence oracle_table_seq
minvalue 1
maxvalue 9999999999999999999999999999
start with 1
increment by 1
nocache
order

本文探讨了在Java开发中如何使用Mybatis通过CLOB类型进行批量插入,重点关注了在处理有序序列时仅begin...end有效的方法。作者分享了详细的Mybatis映射文件和实体类实例,以及表结构和序列设置。
2377

被折叠的 条评论
为什么被折叠?



