首页 > 数据库 > Oracle > 关于oracle with table as的用法
做者:iamlaosong
最远在论坛常常看到有人应用with table as语句,一样泛泛都是构建一个且则表,用于测试,经研究此语句的用法我理解有以下益处:
1)
例如:with
select
select"020 82167684"from
select"010-6210214762104404"from
select"0860476-82321383"from
select"020-28876096"from
select"010-67260464-分机"from
select
--对各类花式德律风号码做典范化措置
2)
3)
例如:
with a as (select * from
dba_objects where 某些查询条件),
再比如:
with tb as (select * from
dba_objects where 某些查询条件),
1、with table as 相当于建个且则表(用于一个语句中某些中间成效放在且则表空间的SQL语句),Oracle 9i 新删WITH语法,可以也许将查询中的子查询命名,放到SELECT语句的最前面。
语法便是
with
tempname as (select ....)
select ...
例子:
with t as (select * from emp where depno=10)
select * from t where empno=xxx
with wd as (select
did,arg(salary) 仄均工资 from work group by did),
em as (select emp.*,w.salary from emp left join work w on emp.eid =
w.eid)
select * from wd,em where wd.did =em.did and
wd.仄均工资>em.salary;
2、甚么时间被覆灭
且则表没有都是会话结束便自动被PGA覆灭嘛! 但with as且则表是查询完成后便被覆灭了!
23:48:58
23:57:58
---------- -------------- -------------
已用年光光阴:
23:58:06
select * from aa
第 1 止呈现偏差:
ORA-00942: 表或视图没有存在
已用年光光阴:
23:58:14
3、举例
假定有张很大的表,有几年往的运营数据,数据量很大。假设要统计一段年光光阴内的邮件状况,假设都从总表中统计,效力一定没有高,而采取with tablename as 语句,先将一段年光光阴内的数据与出往,再进止统计便会简单的多。
with tb as (
select b.city,a.mail_num,a.rcv_area from tb_evt_mail_clct a, tb_jg b
select aa.city 收寄都会, aa.wtt 已妥投, bb.wtd 已投递, cc.wkc 已开拆
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22981660/viewspace-1115682/ ,如需转载,请注明出处,否则将追究法律责任。