zoukankan      html  css  js  c++  java
  • MyBatis学习 之 七、mybatis各种数据库的批量修改

                                     

      MyBatis的update元素的用法与insert元素基本相同,因此本篇不打算重复了。本篇仅记录批量update操作的sql语句,懂得SQL语句,那么MyBatis部分的操作就简单了。

    注意:下列批量更新语句都是作为一个事务整体执行,要不全部成功,要不全部回滚。

    二、MSSQL的SQL语句                          

    复制代码
    WITH R AS(
      SELECT 'John' as name, 18 as age, 42 as  id
      UNION ALL
      SELECT 'Mary' as name, 20 as age, 43 as  id
      UNION ALL
      SELECT 'Kite' as name, 21 as age, 44 as  id
    )
    UPDATE TStudent SET name = R.name, age = R.age
    FROM R WHERE R.id = TStudent.Id
    复制代码

    三、MSSQL、ORACLE和MySQL的SQL语句                

    复制代码
    UPDATE TStudent SET Name = R.name, Age = R.age
    from (
    SELECT 'Mary' as name, 12 as age, 42 as id
    union all
    select 'John' as name , 16 as age, 43 as id
    ) as r 
    where ID = R.id
    复制代码

    四、SQLITE的SQL语句                          

    当条更新:

    REPLACE INTO TStudent(Name, Age, ID)
    VALUES('Mary', 12, 42)

    批量更新:

    REPLACE INTO TStudent(Name, Age, ID)
    SELECT * FROM (
     select 'Mary' as a, 12 as b, 42 as c
     union all
     select 'John' as a, 14 as b, 43 as b
    ) AS R

    说明:REPLACE INTO会根据主键值,决定执行INSERT操作还是UPDATE操作。

    五、总结                                  

      本篇突出MyBatis作为半自动ORM框架的好处了,全手动操控SQL语句怎一个爽字了得。但对码农的SQL知识要求也相对增加了不少,倘若针对项目要求再将这些进行二次封装那会轻松比少。

      尊重原创,转载请注明来自:http://www.cnblogs.com/fsjohnhuang/p/4078999.html  ^_^肥仔John

    六、参考                                  

    http://feng10251225.blog.163.com/blog/static/6312279820114302391320/

    http://www.cnblogs.com/liping13599168/archive/2011/05/24/2054908.html

    如果您觉得本文的内容有趣就扫一下吧!捐赠互勉!

  • 相关阅读:
    caffe用到的命令和零碎知识
    Manjaro — ssh出现22端口拒绝访问问题(port 22: Connection refused)
    Linux 解压z01 .z02 .z03... zip分卷
    Manjaro_Windows双系统安装
    Linux 的chsh命令
    mat2json, python读取mat成字典, 保存json
    最便捷的caffe编译方法 ---- cmake+anaconda虚拟环境
    复制跳过软链接
    使用Screen解决ssh连接中断导致的训练中断问题
    Caffe训练时Loss=87.3365问题
  • 原文地址:https://www.cnblogs.com/shangxiaofei/p/5302256.html
Copyright © 2011-2022 走看看