下面給大家介紹mybatis foreach批量插入數(shù)據(jù):Oracle與MySQL不同點(diǎn):
•主要不同點(diǎn)在于foreach標(biāo)簽內(nèi)separator屬性的設(shè)置問(wèn)題:
•separator設(shè)置為","分割時(shí),最終拼接的代碼形式為:insert into table_name (a,b,c) values (v1,v2,v3) ,(v4,v5,v6) ,...
•separator設(shè)置為"union all"分割時(shí),最終拼接的代碼形式為:insert into table_name (a,b,c) values (v1,v2,v3) union all (v4,v5,v6) union all...
•詳情請(qǐng)見(jiàn)示例代碼:
Oracle:
1
2
3
4
5
6
7
8
9
10
|
< 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:
1
2
3
4
5
6
7
|
< 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 > |
總結(jié)
以上所述是小編給大家介紹的mybatis foreach批量插入數(shù)據(jù):Oracle與MySQL區(qū)別,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!