zoukankan      html  css  js  c++  java
  • oracle多表关联多字段update

    多表关联多字段update

    有代码有J8:

    update spatial_references
    set(
    auth_name, 
    auth_srid, 
    falsex, 
    falsey, 
    xyunits, 
    falsez, 
    zunits, 
    falsem, 
    munits, 
    xycluster_tol, 
    zcluster_tol, 
    mcluster_tol, 
    object_flags, 
    srtext
    )=(select  
    auth_name, 
    auth_srid, 
    falsex, 
    falsey, 
    xyunits, 
    falsez, 
    zunits, 
    falsem, 
    munits, 
    xycluster_tol, 
    zcluster_tol, 
    mcluster_tol, 
    object_flags, 
    srtext
    from spatial_references where srid=0)
    where srid=2;

    ===============================================
    2016.07.09
    以上这条语句不够实用。今天有同事问到,结果露怯,于是发粪涂墙,狂搜资料,又写了一条实用一点的:

    update qq q set 证书GUID=(select zs.guid from 证书表 zs where zs.code=q.证书编号 and rownum=1)

    更完整一点的:

    update qq q set 证书GUID=(select zs.guid from 证书表 zs where zs.code=q.证书编号 and rownum=1)
    where exists(select 1 from 证书表 zs where zs.code=q.证书编号 and zs.guid<>q.证书GUID)
    update nodeconfiginfo n set (qh_name,qh_parentid,qh_orderid)=(select qh_name,qh_parentid,qh_orderid
    from SeaBoardConfig s where s.qh_id=n.qh_id)
    where exists(select 1 from SeaBoardConfig s where s.qh_id=n.qh_id);

    这条语句,SET里有个循环;然后外层也有个循环。这两个循环没有什么直接关系。我不知道这条SQL语句是如何执行的,猜想应该是嵌套循环:

    foreach()
    {//外层循环
        foreach()
        {//set循环
        }
    }

    如果没有外层循环的话,那么会全表执行。

  • 相关阅读:
    快速幂
    Oracle悲观锁和乐观锁
    UTL_RAW的问题?
    Linux操作系统下关于Top命令的参数详解
    存储过程与函数
    网站前端优化一些小经验
    Java获取各种常用时间方法2
    Pro CSS Techniques 读书笔记(六)
    Java获取各种常用时间方法
    Oracle专用服务器与共享服务器的区别
  • 原文地址:https://www.cnblogs.com/leftfist/p/6808711.html
Copyright © 2011-2022 走看看