MyBatis往Oracle数据库批量插入数据

MyBatis往Oracle数据库批量插入数据

  • 使用union all 来串连每个values,其中jdbcType的设置可以使null值也输入进去

    INSERT INTO DDZHPT.CMS_SCHEDUAL_DETIAL
    (
        DEPT_ID,
        SCHEDUAL_DATE,
        CMS_SCHEDUAL_TYPE_ID,
        CMS_SCHEDUAL_TEAM_ID,
        CMS_SCHEDUAL_TYPE_PERIOD_ID,
        CMS_SCHEDUAL_TIME_ID,
        SYS_POST_ID,
        POINT_ID,
        PERSON_ID
    )
   
    SELECT
   	#{item.deptId,jdbcType=DECIMAL},
   	#{item.schedualDate,jdbcType=TIMESTAMP},
   	#{item.cmsSchedualTypeId,jdbcType=VARCHAR},
   	#{item.cmsSchedualTeamId,jdbcType=VARCHAR},
   	#{item.cmsSchedualTypePeriodId,jdbcType=VARCHAR},
   	#{item.cmsSchedualTimeId,jdbcType=VARCHAR},
   	#{item.sysPostId,jdbcType=VARCHAR},
   	#{item.pointId,jdbcType=VARCHAR},
   	#{item.personId,jdbcType=VARCHAR}
    FROM DUAL
   

  • 纯粹使用foreach

    
    INSERT INTO DDZHPT.CMS_SCHEDUAL_DETIAL
    (
        DEPT_ID,
        SCHEDUAL_DATE,
        CMS_SCHEDUAL_TYPE_ID,
        CMS_SCHEDUAL_TEAM_ID,
        CMS_SCHEDUAL_TYPE_PERIOD_ID,
        CMS_SCHEDUAL_TIME_ID,
        SYS_POST_ID,
        POINT_ID,
        PERSON_ID
    )
    VALUES(
        #{item.deptId,jdbcType=DECIMAL},
        #{item.schedualDate,jdbcType=TIMESTAMP},
        #{item.cmsSchedualTypeId,jdbcType=VARCHAR},
        #{item.cmsSchedualTeamId,jdbcType=VARCHAR},
        #{item.cmsSchedualTypePeriodId,jdbcType=VARCHAR},
        #{item.cmsSchedualTimeId,jdbcType=VARCHAR},
        #{item.sysPostId,jdbcType=VARCHAR},
        #{item.pointId,jdbcType=VARCHAR},
        #{item.personId,jdbcType=VARCHAR}
    )
    

 

你可能感兴趣的:(MyBatis)