使用Mybatis 对Oracle数据库进行批量新增和批量修改

使用Mybatis操作Oracle对同一表进行批量新增和批量修改与Mysql是有区别的。

批量新增

SEQ_ANSWER_ID自增序列,SEQ_ANSWER_ID.Nextval是下一个要添加的ANSWER_ID,
有序列操作的可以这样些,没有序列操作的,可以把 ANSWER_ID字段和 SEQ_ANSWER_ID.Nextval去掉。


       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 
         (
         
        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
        
         ) c
   

批量修改,Oracle 以begin开始,end结束


         begin 
         
            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} 
          
          ;end;
   

你可能感兴趣的:(使用Mybatis 对Oracle数据库进行批量新增和批量修改)