引用:
with
e as (select * from scott.emp),
d as (select * from scott.dept)
select e.字段1,d.字段1
from e,d
where e.id=d.id
–相当于建个e临时表with e as (select * from scott.emp e where e.empno=7499)select * from e;
–相当于建e、d临时表withe as (select * from scott.emp),d as (select * from scott.dept)select * from e, d where e.deptno = d.deptno;
其实就是把一大堆重复用到的sql语句放在with as里面,取一个别名,后面的查询就可以用它,这样对于大批量的sql语句起到一个优化的作用,而且清楚明了。
优点:
WITH语句的优点:
(1). SQL可读性增强。比如对于特定with子查询取个有意义的名字等。
(2)、with子查询只执行一次,将结果存储在用户临时表空间中,可以引用多次,增强性能。