Oracle with语句是经常可以见到的语句,下面就为您详细介绍Oracle with语句的用法,如果您对Oracle with语句感兴趣的话,不妨一看。
当查询中多次用到某一部分时,可以用Oracle with语句创建一个公共临时表。因为子查询在内存临时表中,避免了重复解析,所以执行效率会提高不少。临时表在一次查询结束自动清除。
一般语法格式:
- with
- alias_name1 as (subquery1),
- alias_name2 as (subQuery2),
- ……
- alias_nameN as (subQueryN)
- select col1,col2…… col3
- from alias_name1,alias_name2……,alias_nameN
Oracle with语句的例子:
- SQL> WITH
- Q1 AS (SELECT 3 + 5 S FROM DUAL),
- Q2 AS (SELECT 3 * 5 M FROM DUAL),
- Q3 AS (SELECT S, M, S + M, S * M FROM Q1, Q2)
- SELECT * FROM Q3;
输出结果:
- S M S+M S*M
- ---------- ---------- ---------- ----------
- 8 15 23 120
【编辑推荐】