• mybatis批量插入:oracle和mysql的区别


    一、oracle批量插入

     <insert id="save" parameterType="java.util.List">
     
             insert into student
             (name,age)
    
             <foreach collection="list" item="item" index="index" separator="union all">
                 (
                 select
                 #{item.name,jdbcType=VARCHAR}, #{item.age,jdbcType=INTEGER}
            from dual
    ) </foreach> </insert>

    二、mysql批量插入

      <insert id="save" parameterType="java.util.List">
      
              insert into student
              (name,age)
           values
              <foreach collection="list" item="item" index="index" separator="," close=";">
                 #{item.name,jdbcType=VARCHAR}, #{item.age,jdbcType=INTEGER}
             </foreach>
     </insert>

    总结:

      1、oracle中没有values关键字

      2、oracle的foreach中的separator值是UNION ALL ,mysql的foreach中的separator值是逗号

      3、oracle的foreach中的语句需要(select ...from dual)包裹。(括号可以直接加在这里,也可以加在foreach中,open="(" close=")"

  • 相关阅读:
    新浪微博学习的知识点
    新浪项目笔记
    2015年10月20日整理知识
    版本管理工具 (git 或者 svn)
    Coding 代码push/commit/pull/git clone
    fileurlwithpath urlwithstring 这俩有啥区别吗
    正则表达式
    地图
    各种杂项
    实时通讯
  • 原文地址:https://www.cnblogs.com/guduershi/p/10038534.html
Copyright © 2020-2023  润新知