zoukankan      html  css  js  c++  java
  • oracle和mysql中update联表批量更新数据的区别

    之前碰到一个sql语句,在oracle中可以运行,在mysql上就不行,后来查了好久,发现了他们两个联表批量更新数据的区别如下:

    (借鉴一下别人的例子)

    update :单表的更新不用说了,两者一样,主要说说多表的更新
    复制代码 代码如下:       

    Oracle> Oracle的多表更新要求比较严格,所以有的时候不是很好写,我们可以试试Oracle的游标
            update (
            select t.charger_id_ new_charger_id_ 
            from t_cus_year_status t 
            left join t_customer_infos cus on cus.id_ = t.cus_id_
            where....
            ) n  set  n.new_charger_id_ =6;
    
    复制代码 代码如下:
    mysql> 
          update t_cus_year_status t 
          left join t_customer_infos cus on cus.id_ = t.cus_id_
          set t.charger_id_  =6
          where......;
    

      然后仔细观察,可以看出,mysql的更新与oracle不同,是必须要先join on来进行联表,然后才set的,不然就会报语法错误。

    附上我写的sql,是一个三表联查

    UPDATE bm_crm_archive_info t join (select DATE(now()) date_check,
    t2.oper_per,t2.check_per,t1.pkg_code,t2.app_id 
    from bm_crm_apply_rel_info t1 join bm_crm_archive_out_apply t2 on t1.app_id = t2.app_id) y on t.pkg_code = y.pkg_code 
    join bm_crm_archive_out_apply tt on y.app_id=tt.app_id and y.app_id = '4' 
    set t.out_per = y.oper_per,t.out_checker = y.check_per,t.out_date=y.date_check,t.status=4,tt.app_status=3
    where y.app_id = '4' and y.app_id=tt.app_id
  • 相关阅读:
    完整java开发中JDBC连接数据库代码和步骤
    2007最后一贴
    ajax数据加载经验分享
    vs2008中文版提供下载(包含中文msdn)
    修改服务器控件的ID和Name
    你使用控件吗?会用吗?
    自定义控件集
    asp.net控件开发基础示例代码打包
    javascript好文章收藏
    wpf学习笔记简单绑定
  • 原文地址:https://www.cnblogs.com/yufengwang/p/12161356.html
Copyright © 2011-2022 走看看