Mybatis批量插入或更新使用MERGE INTO

     MERGE INTO employee A1
        USING
        (
           <foreach close="" collection="list" index="index" item="item" open="" separator="union">
             select  #{item.id} id,#{item.name} name,#{item.deptId} deptId,#{item.deptName} deptName from dual
           </foreach>
        ) A2
        ON
        (
           A1.id = A2.id
        )
        WHEN MATCHED THEN
        UPDATE SET A1.status = 1
        WHEN NOT MATCHED THEN
        INSERT
        (id,name,detp_id,dept_name)
        VALUES( A2.id,A2.name,A2.deptId,A2.deptName)

猜你喜欢

转载自blog.csdn.net/weixin_40333020/article/details/80637359