zoukankan      html  css  js  c++  java
  • With as 必须跟select

    update b set b.object_name=(select a.object_name from a where a.object_id=b.object_id);
    
    create table a as (select * from (select * from dba_objects order by object_id) where rownum<100)
    
    
    create table b as (select * from (select * from dba_objects order by object_id) where rownum<100)
    
    
    SQL> update b set object_name=object_name||'xxx';
    
    99 rows updated.
    
    
    SQL> select count(*) from a;
    
      COUNT(*)
    ----------
    	99
    
    子查询会被扫描99次
    
    SQL> alter session set statistics_level=all;
    
    Session altered.
    
    SQL> update b set b.object_name=(select a.object_name from a where a.object_id=b.object_id);
    
    99 rows updated.
    
    SQL> select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'));
    
    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    --------------------------------------------
    SQL_ID	9n2d868fqhcq4, child number 0
    -------------------------------------
    update b set b.object_name=(select a.object_name from a where
    a.object_id=b.object_id)
    
    Plan hash value: 1917715316
    
    -------------------------------------------------------------------------------------
    | Id  | Operation	   | Name | Starts | E-Rows | A-Rows |	 A-Time   | Buffers |
    -------------------------------------------------------------------------------------
    |   0 | UPDATE STATEMENT   |	  |	 1 |	    |	   0 |00:00:00.01 |	504 |
    |   1 |  UPDATE 	   | B	  |	 1 |	    |	   0 |00:00:00.01 |	504 |
    |   2 |   TABLE ACCESS FULL| B	  |	 1 |	 99 |	  99 |00:00:00.01 |	  4 |
    |*  3 |   TABLE ACCESS FULL| A	  |	99 |	  1 |	  99 |00:00:00.01 |	396 |
    -------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - filter("A"."OBJECT_ID"=:B1)
    
    Note
    -----
       - dynamic sampling used for this statement (level=2)
    
    
    25 rows selected.
    
    
    可以看到A表被扫描了99次,类似于NL。
    
    
    
    改为with as 呢?
    
    with  A as (select a.object_name from a )
    update b set b.object_name=a.object_name 
    where  a.object_id=b.object_id;
    
    SQL> with  A as (select a.object_name from a )
    update b set b.object_name=a.object_name 
    where  a.object_id=b.object_id;  2    3  
    update b set b.object_name=a.object_name
    *
    ERROR at line 2:
    ORA-00928: missing SELECT keyword
    
    with as 必须紧跟引用的select 语句,而不是delete update merge
    

  • 相关阅读:
    网上邻居无法打开的问题 客户端无法连接打印机问题
    今天一天下午到晚上都在研究如何刷手机,要是被领导知道我帮同学在刷手机系统,非开除我不可。还是贴出来,以后少走弯路吧
    “屏幕保护程序”没有出现“在恢复时使用密码保护”的解决方法
    NOD 32客户端安装时出现的问题
    [模板]二叉树的前、中、后序遍历
    [算法]浅谈求n范围以内的质数(素数)
    [模板]二叉搜索树
    [OI]Noip 2018 题解&总结(普及)
    Centos7.2安装git(源码安装)
    Centos7.2安装maven
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351946.html
Copyright © 2011-2022 走看看