mysql
<insert id="addHandSyncArea" parameterType="com.bn.acm.base.po.AreaManagePo">
insert
into
sky_area_route(
code,
name,
significance,
area,
vesting_area,
child_area,
remark,
feature_type,
area_feature,
color,
is_deleted,
area_scope
)
values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.code,jdbcType=VARCHAR},
#{item.name,jdbcType=VARCHAR},
#{item.significance,jdbcType=VARCHAR},
#{item.area,jdbcType=VARCHAR},
#{item.vestingArea,jdbcType=VARCHAR},
#{item.childArea,jdbcType=VARCHAR},
#{item.remark,jdbcType=VARCHAR},
#{item.featureType,jdbcType=VARCHAR},
#{item.areaFeature,jdbcType=VARCHAR},
#{item.color,jdbcType=VARCHAR},
'0',
#{item.areaScope,jdbcType=VARCHAR}
)
</foreach>
</insert>
Oracle
区别:1.SQL中没有VALUES;
2.标签中的(selece ..... from dual);
3.标签中的separator的属性为"UNION ALL",将查询合并结果集。
方法一(此方法插入的clob字段超高4000长度时会报错):
<insert id="addHandSyncArea" parameterType="com.bn.acm.base.po.AreaManagePo">
insert
into
sky_area_route(
code,
name,
significance,
area,
vesting_area,
child_area,
remark,
feature_type,
area_feature,
color,
is_deleted,
area_scope
)
<foreach collection="list" item="item" separator="UNION ALL">
(
select
#{item.code,jdbcType=VARCHAR},
#{item.name,jdbcType=VARCHAR},
#{item.significance,jdbcType=VARCHAR},
#{item.area,jdbcType=VARCHAR},
#{item.vestingArea,jdbcType=VARCHAR},
#{item.childArea,jdbcType=VARCHAR},
#{item.remark,jdbcType=VARCHAR},
#{item.featureType,jdbcType=VARCHAR},
#{item.areaFeature,jdbcType=VARCHAR},
#{item.color,jdbcType=VARCHAR},
'0',
#{item.areaScope,jdbcType=VARCHAR}
from dual
)
</foreach>
</insert>
方法二(解决方法一报错):
<insert id="addHandSyncArea" parameterType="com.bn.acm.base.po.AreaManagePo">
begin
<foreach collection="list" item="item" index="index" separator=";">
insert
into
sky_area_route(
code,
name,
significance,
area,
vesting_area,
child_area,
remark,
feature_type,
area_feature,
color,
is_deleted,
area_scope
)
values(
#{item.code,jdbcType=VARCHAR},
#{item.name,jdbcType=VARCHAR},
#{item.significance,jdbcType=VARCHAR},
#{item.area,jdbcType=VARCHAR},
#{item.vestingArea,jdbcType=VARCHAR},
#{item.childArea,jdbcType=VARCHAR},
#{item.remark,jdbcType=VARCHAR},
#{item.featureType,jdbcType=VARCHAR},
#{item.areaFeature,jdbcType=VARCHAR},
#{item.color,jdbcType=VARCHAR},
'0',
#{item.areaScope,jdbcType=VARCHAR}
)
</foreach>
;end;
</insert>