본문 바로가기
mybatis

[ORACLE,MYSQL] 배열 insert update

by 뇽꾸리 2022. 10. 4.
반응형

-- ORACLE 

 

 <insert id="insert">
        <foreach collection="arr" item="item" open="INSERT ALL" close="SELECT * FROM DUAL" separator=" ">
             INSERT INTO TEST_TABLE(
                 ITEM
                , REG_DT
                , REG_ID
                , USE_YN
                , UPDATE_ID
                , UPDATE_DT
            ) VALUES (
                 #{item}
                , CURRENT_DATE
                , #{regId}
                , #{useYn}
                , #{updateId}
                , CURRENT_DATE
            )
        </foreach>
    </insert>
 <update id="update">
        <foreach collection="list" item="item" separator=";" open="DECLARE BEGIN" close="; END;">
            UPDATE TEST_TABLE
                SET
                    TEST_CMM =#{item.testCmm}
            <where>
                TEST_ID =#{item.testId}
            </where>
        </foreach>
    </update>

 

 

-- MYSQL

<insert id="insert">
    INSERT INTO TEST_TABLE(
          ITEM_KEY
        , ITEM_VALUE
    ) VALUES 
    <foreach collection="arrOrList" item="item" separator=",">
    (
          #{item.idx}
        , #{item.value}
    )
    </foreach>
</insert>

 

 

<selectKey resultType="String" keyProperty="ID" order="AFTER"> 
    SELECT MAX (ID) FROM TABLE
</selectKey>

 @Transactional
    public void save(ReqModel reqModel) {

        mapper.insert(reqModel);       
        System.out.println(reqModel.getId());

    }
반응형

'mybatis' 카테고리의 다른 글

pageHelper + springBoot + mybatis  (0) 2022.07.07

댓글