oracle with as用法

来源:互联网 发布:合肥软件开发待遇 编辑:程序博客网 时间:2024/06/05 07:41
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),   …


--相当于建了个e临时表with e as (select * from scott.emp e where e.empno=7499)select * from e; --相当于建了e、d临时表with     e 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 as优点
增加了sql的易读性,如果构造了多个子查询,结构会更清晰;
更重要的是:“一次分析,多次使用”,这也是为什么会提供性能的地方,达到了“少读”的目标










0 0
原创粉丝点击