mybatis foreach批量插入数据:Oracle与MySQL不同点:

  • 主要不同点在于foreach标签内separator属性的设置问题:

    1. separator设置为","分割时,最终拼接的代码形式为:insert into table_name (a,b,c) values (v1,v2,v3) ,(v4,v5,v6) ,...
    2. separator设置为"union all"分割时,最终拼接的代码形式为:insert into table_name (a,b,c) values (v1,v2,v3) union all (v4,v5,v6) union all...
  • 详情请见示例代码:

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>

最新文章

  1. 【CentOS】LAMP相关3
  2. SQL 数字分割的字符串
  3. HIFI播放器--磨机吐槽篇
  4. MyEclipse无法启动调试:Cannot connect to VM
  5. JAVA基础学习之throws和throw的区别、Java中的四种权限、多线程的使用等(2)
  6. Get Many Persimmon Trees_枚举&amp;&amp;二维树状数组
  7. &lt;转&gt;单播,广播,组播的缺点与优点
  8. WWDC 2016: Rich Notifications in iOS 10
  9. CodeForces 609A USB Flash Drives
  10. div内部元素居中
  11. yum安装phpmyadmin小问题
  12. 面向对象object与constructor
  13. php 逗号 explode分割字符串 或 implode组装成字符串
  14. IIS日志存入数据库之一:ODBC
  15. tensorflow进阶篇-4(损失函数3)
  16. Vue之组件使用(一)
  17. 强制开启android webview debug模式使用Chrome inspect
  18. python-day21--os模块
  19. 文本操作 $(..).text() $(..).html() $(..).val()最后一种主要用于input
  20. Hibernate入门级实例

热门文章

  1. 《Head First 设计模式》【PDF】下载
  2. iOS学习之Socket使用简明教程- AsyncSocket
  3. 关于《ASP.NET MVC企业级实战》
  4. Handler的解析和使用
  5. laravel框架一种方便的快速填充数据的方法
  6. ABP 教程文档 1-1 手把手引进门之 AngularJs, ASP.NET MVC, Web API 和 EntityFramework(官方教程翻译版 版本3.2.5)含学习资料
  7. VS 2017 Web项目需要安装Sql Server 2012 Express LocalDB问题
  8. 麻瓜之我要学sql,啦啦啦啦
  9. JDK并发包常用的知识图
  10. 快速恢复开发环境(系统还原后的思考,附上eclipse注释的xml配置文件)