Oracle 高階查詢

2021-07-31 11:51:49 字數 1104 閱讀 2446

語法:    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語句建立乙個公共臨時表。

因為子查詢在記憶體臨時表中,避免了重複解析,所以執行效率會提高不少。臨時表在一次查詢結束自動清除。

with clause方法的優點

增加了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

union/union all

一去重,二不去重直接並集

intersect

取二者的交集

minus

取二者的差集

select employee_id,department_id

from employees01

union/union all/intersect/minus

select employee_id,department_id

from employees02

ORACLE 高階查詢

oracle 高階查詢 1.集合操作 並集 交集 補集 1 union 並集 不重複 select dept code,dept name from base dept union select dept code,dept name from geyy dept 2 union all 並集 重複...

oracle 高階查詢

一.使用集合操作符 1.union all 返回各個查詢檢索出的所有行,包括重複的行 2.union 返回查詢檢索出的所有非重複行 3.intersect 返回兩個查詢檢索出的共有行 4.minus 返回從第乙個查詢檢索出的行中減去第二個查詢檢索出的行之後剩餘的行。二.translate 函式 tr...

ORACLE高階查詢

1.connect by 是乙個連續的 select regexp substr 01 02 03 04 1,level as newport from dual connect by level regexp count 01 02 03 04 1.0select regexp substr 由店...