使用Mybatis操作Oracle对同一表进行批量新增和批量修改与Mysql是有区别的。
批量新增
SEQ_ANSWER_ID自增序列,SEQ_ANSWER_ID.Nextval是下一个要添加的ANSWER_ID,
有序列操作的可以这样些,没有序列操作的,可以把 ANSWER_ID字段和 SEQ_ANSWER_ID.Nextval去掉。
<insert id="insertAnswerList" parameterType="java.util.List">
insert into T_E_QUESTION_ANSWER (
ANSWER_ID,
CREATED_BY,
CREATED_DATE,
UPDATED_BY,
UPDATED_DATE,
POLICY_ID
)
select SEQ_ANSWER_ID.Nextval,c.* from
(
<foreach collection="list" index="index" item="item" separator="union all">
select
#{item.createdBy,jdbcType=VARCHAR} as createdBy,
sysdate as createdDate,
#{item.updatedBy,jdbcType=VARCHAR} as updatedBy,
sysdate as updatedDate,
#{item.policyId} as policyId
from dual
</foreach>
) c
</insert>
批量修改,Oracle 以begin开始,end结束
<update id="updateQuotationQuestionAnswerList" parameterType="java.util.List">
begin
<foreach collection="list" item="item" separator=";">
update T_E_QUOTATION_QUESTION_ANSWER
set ANSWER = #{item.answer,jdbcType=INTEGER},
DISEASE_CURE = #{item.diseaseCure,jdbcType=VARCHAR},
DISEASE_BEGIN_TIME = #{item.diseaseBeginTime,jdbcType=VARCHAR},
CURE_RESULT = #{item.cureResult,jdbcType=VARCHAR},
HOSPITAL_DOCTOR = #{item.hospitalDoctor,jdbcType=VARCHAR},
PART_D_ANSWER = #{item.partDAnswer,jdbcType=VARCHAR},
UPDATED_BY = #{item.updatedBy,jdbcType=VARCHAR},
UPDATED_DATE = sysdate
where ANSWER_ID = #{item.answerId}
</foreach>
;end;
</update>
网友评论