首页 > 数据库技术 > 详细

mybatis支持oracle批量插入

时间:2016-07-11 12:17:03      阅读:134      评论:0      收藏:0      [点我收藏+]

问题:mysql使用mybatis批量插入时,通过foreach标签,将每条记录按照逗号","连接即可。

但是,oracle不支持。

 

oracle支持如下写法:

 

<insert id="insertStudents">
        INSERT INTO Student
            (
                id, 
                name, 
                age, 
                sex
            )
        <foreach collection="stuList" item="item" index="index" separator="union all" > 
              (
                  select  
                      #{item.id,jdbcType=VARCHAR},
                    #{item.name,jdbcType=VARCHAR},
                    #{item.age,jdbcType=VARCHAR},
                    #{item.sex,jdbcType=VARCHAR}
                from dual
               )
        </foreach>
       </insert>

 

其中dao的写法如下:

public void insertStudents(@Param("stuList") List<Student> stuList);

 

 

 

知识点:

oracle给字段起有空格的别名:select count(*)  as "my sum" from student;   使用双引号""。

 

mybatis支持oracle批量插入

原文:http://www.cnblogs.com/xxyfhjl/p/5659524.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!