Mybatis批量增加,删除,更新Oracle
2014-11-05 10:19
316 查看
Mybatis批量增加,删除,更新Oracle
最近需要用到Mybatis批量新增oracle数据库,刚开始在网上找到的方法是都是更新mySQL的,试了一下发现不适合Oracle,后来发现正确的oracle批量新增的sql是:<insert id="insertAttractionsBatch" parameterType="java.util.List">
insert into ATTRACTIONS (
ID, NAME, LONGITUDE, LATITUDE, UPDATE_TIME
)
<foreach collection="list" item="item" index="index" separator="union all" >
(select
#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.longitude,jdbcType=DECIMAL}, #{item.updateTime,jdbcType=TIMESTAMP}
from dual)
</foreach>
</insert>
需要重点注意的是sql中没有values,和<foreach>标签中的(selece ..... from dual),MySql中的sql是这样的:
新增:
<insert id="insertAttractionsBatch" parameterType="java.util.List">
insert into ATTRACTIONS (
ID, NAME, LONGITUDE, LATITUDE, UPDATE_TIME
)
<foreach collection="list" item="item" index="index" separator="union all" >
#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.longitude,jdbcType=DECIMAL}, #{item.updateTime,jdbcType=TIMESTAMP}
</foreach>
</insert>
oracle更新不能按普通的方式,需要这样:
<update id="updateAttractionsBatch" parameterType="java.util.List">
begin
<foreach collection="list" item="item" index="index" separator=";" >
update ATTRACTIONS
<set>
<if test="item.id!=null and item.id!=''">
id = #{item.id},
</if>
<if test="item.head!=null and item.head!=''">
HEAD = #{item.head},
</if>
</set>
where id = #{item.id}
</foreach>
;end;
</update>
删除就与MySql一样了如下:
<delete id="deleteAttractions" parameterType="java.util.List">
delete from ATTRACTIONS
<where>
<foreach collection="list" index="index" item="item" open="(" separator="or" close=")">
id=#{item.id}
</foreach>
</where>
</delete>
相关文章推荐
- Mysql和Oracle 用Mybatis批量增加,删除,更新
- Mybatis批量增加,删除,更新Oracle
- Mybatis批量增加,删除,更新Oracle
- Mybatis批量增加,删除,更新Oracle
- Mybatis批量增加,删除,更新Oracle
- Mybatis批量增加,删除,更新Oracle
- Mybatis批量增加,删除,更新Oracle
- oracle和mysql在创建表、更新表(增加、修改、删除字段)、删除表的区别与联系
- Mybatis批量增加、批量更新、批量删除和查询
- 使用XmlDocument创建XML文档及增加删除更新节点
- Oracle中使用alter table来增加,删除,修改列的语法
- 关联关系的crud(增加(Create)、查询(Retrieve)(重新得到数据)、更新(Update)和删除(Delete))的理解(casecade和fetch)
- Oracle定时删除、增加表分区
- 数据库中两张表之间的数据同步增加、删除与更新
- Oracle增加删除主键
- ORACLE 删除,更新,添加注释
- Entity Framework 学习初级篇7--基本操作:增加、更新、删除、事务
- Oracle 参数 游标[游标更新删除数据]
- 使用XmlDocument创建XML文档及增加删除更新节点
- oracle修改表增加列删除列修改列