Here is a description of mybatis foreach batch insertion data: the differences between Oracle and MySQL:
•The main difference lies in the problem of setting the separator attribute in the foreach tag:
•When separator is set to "," segmentation, the final splicing code form is: insert into table_name (a,b,c) values (v1,v2,v3) ,(v4,v5,v6) ,...
•When separator is set to "union all" to split, the final splicing code form is: insert into table_name (a,b,c) values (v1,v2,v3) union all (v4,v5,v6) union all...
•For details, please see the sample code:
Oracle:
<insert id="inserData" parameterType="com.test.aaa.Bac"> insert into table_name (name, address, 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, address, age) values <foreach collection="list" item="item" index="index" separator=","> ( #{item.name}, #{item.adress}, #{item.age} ) <foreach></insert> Summarize
The above is the batch insertion data of mybatis foreach introduced to you by the editor: the difference between Oracle and MySQL, I hope it will be helpful to everyone. If you have any questions, please leave me a message. The editor will reply to everyone in time!