The foreach loop (oracle database) is used when using mybatis to customize SQL in my recent work, but the following writing is not easy to use:
<insert id="insertBatch" parameterType="java.util.List">
insert INTO
user_tb
(user_id,
user_name,
user_age)
<foreach collection="list" item="item" separator="union all">
select
#{item.userId},
#{item.userName},
#{item.userAge}
FROM dual
</foreach>
</insert>
A colleague reminded me to write:
<insert id="insertBatch" parameterType="java.util.List" useGeneratedKeys="false">
insert INTO
user_tb
(user_id,
user_name,
user_age)
<foreach collection="list" item="item" separator="union all">
select
#{item.userId},
#{item.userName},
#{item.userAge}
FROM dual
</foreach>
</insert>
The use of self-incrementing primary keys in oracle database requires the use of sequences or other methods, and does not support automatic generation.