MyBatis foreach BULK INSERT data: Oracle differs from MySQL:
- The main difference is the setting of the Separator property within the foreach tag:
- Separator is set to "," when split, the final stitching code form is: INSERT INTO table_name (A,B,C) VALUES (v1,v2,v3), (V4,V5,V6),...
- When separator is set to the "union All" split, the final stitching is in the form of INSERT INTO table_name (A,B,C) VALUES (V1,V2,V3) union ALL (V4,V5,V6) union ALL ...
- See the sample code for details:
Oracle:
<insert id="inserData" parameterType="com.test.aaa.Bac"> insert into table_name (name, adress, age) values <foreach collection="list" item="item" index="index" separator="union all"> (select #{item.name}, #{item.adress}, #{item.age} from dual ) <foreach></insert>
Mysql:
<insert id="inserData" parameterType="com.test.aaa.Bac"> insert into table_name (name, adress, age) values <foreach collection="list" item="item" index="index" separator=","> ( #{item.name}, #{item.adress}, #{item.age} ) <foreach></insert>
MyBatis foreach BULK INSERT data: Oracle differs from MySQL