开发中,在有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