oracle 高階查詢

2021-08-10 10:24:09 字數 1501 閱讀 3467

一.使用集合操作符

1.union all:返回各個查詢檢索出的所有行,包括重複的行

2.union:返回查詢檢索出的所有非重複行

3.intersect:返回兩個查詢檢索出的共有行

4.minus:返回從第乙個查詢檢索出的行中減去第二個查詢檢索出的行之後剩餘的行。

二.translate()函式

translate(x,from,to):在x中查詢from中的字元,並將其轉換成to中對應的字元

select translate('hello world', 'abcdefg', 'hijklmn') as test from dual;

test

-----------

hlllo worlk

三.decode()

decode(value,search,result,default):對value與search進行比較。如果兩個值相等,就返回result,否則返回default

注意:decode是oracle特有的函式,9i或者更高版本,用case代替。

select decode(1,2,3,4) from dual;

decode(1,2,3,4)

------------------

4

四.case

case 表示式是在sql中實現if-then-else邏輯。

簡單case表示式,使用表示式確定返回值。

搜尋case表示式,使用條件確定返回值。

簡單case表示式:

語法如下:

case search_expression

when expression1 then result1

when expression2 then result2

...else default_result

end

搜尋case表示式:

語法如下:

case 

when condition1 then result1

when condition2 then result2

...else default_result

end

五:層次化查詢:

樹 使用connect by和start with字句

語法:

select [level], column, expression, ...

from table

[where where_clause]

[[start with start_conditon][connect by prior prior_condition]

2.內聯檢視不能包含對在右外連線或全外連線中的第乙個表的左關聯

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 高階查詢

語法 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高階查詢

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 由店...