加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长百科 > 正文

关于oracle with as用法

发布时间:2021-03-31 07:18:04 所属栏目:站长百科 来源:网络整理
导读:with as语法 –针对一个体名 with tmp as (select * from tb_name) –针对多个体名 with ?? tmp as (select * from tb_name), ?? tmp2 as (select * from tb_name2), ?? tmp3 as (select * from tb_name3), ?? … 1 2 3 4 5 6 7 8 9 --相等于建了个e姑且表 w
1 2 3 4 5 6 7 8 9 10 with????sql1 as? (select? to_char(a) s_name from? test_tempa),????sql2 as? (select? to_char(b) s_name from? test_tempb where? not? exists (select? s_name from? sql1 where? rownum=1))select? * from? sql1union? allselect? * from? sql2union? allselect? ‘no records‘? from? dual???????where? not? exists (select? s_name from? sql1 where? rownum=1)???????and? not? exists (select? s_name from? sql2 where? rownum=1);

with as利益增进了sql的易读性,假如结构了多个子查询,布局会更清楚;更重要的是:“一次说明,多次行使”,这也是为什么会提供机能的处所,到达了“少读”的方针

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

with as短语,也叫做子查询部门(subquery factoring),可以让你做许多工作,界说一个sql片段,该sql片段会被整个sql语句所用到。有的时辰,是为了让sql语句的可读性更高些,也有也许是在union all的差异部门,作为提供数据的部门。
  
出格对付union all较量有效。由于union all的每个部门也许沟通,可是假如每个部门都去执行一遍的话,则本钱太高,以是可以行使with as短语,则只要执行一遍即可。假如with as短语所界说的表名被挪用两次以上,则优化器会自动将with as短语所获取的数据放入一个temp内外,假如只是被挪用一次,则不会。而提醒materialize则是逼迫将with as短语里的数据放入一个全局姑且内外。许多查询通过这种要领都可以进步速率。

热点阅读