ORACLE WITH AS 用法,创建临时表 | 您所在的位置:网站首页 › oracle创建临时表结构 › ORACLE WITH AS 用法,创建临时表 |
语法: with tempName as (select ....)select ...
–针对一个别名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-19中得到11-14。一般的sql如下: ![]() ![]()
With查询语句不是以select开始的,而是以“WITH”关键字开头 可认为在真正进行查询之前预先构造了一个临时表TT,之后便可多次使用它做进一步的分析和处理 WITH Clause方法的优点 增加了SQL的易读性,如果构造了多个子查询,结构会更清晰;更重要的是:“一次分析,多次使用”,这也是为什么会提供性能的地方,达到了“少读”的目标。 第一种使用子查询的方法表被扫描了两次,而使用WITH Clause方法,表仅被扫描一次。这样可以大大的提高数据分析和查询的效率。 另外,观察WITH Clause方法执行计划,其中“SYS_TEMP_XXXX”便是在运行过程中构造的中间统计结果临时表。 、、、、、、、、、、、、、、 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临时表 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用法 1 2 3 4 5 insert into table2 with s1 as (select rownum c1 from dual connect by rownum |
CopyRight 2018-2019 实验室设备网 版权所有 |