有關Oracle 資料庫連線查詢SQL語句

來源:果殼範文吧 2.95W

內連線(inner join)。

有關Oracle 資料庫連線查詢SQL語句

外連線:

全連線(full join)、左連線(left join)、右連線(right join)。

交叉聯接(cross join)。

外連線與內連線不一樣,外連線返回的查詢結果中不僅包含符合條件的行,還包括左表(左外連線),右表(右外連線)或者兩個連線表(全外連線)中的所有不符合條件的資料行。

 1.左連線 (left [outer] join)

左外連線就是將左表的所有資料分別於右表的每條資料進行連線組合,返回的結果除內連線的資料外,還有左表中不符合條件的資料,並在右表的相應列中填上null值。

SQL語句如下:

select * from mt_pb_org o left join mt_pb_orgframe f on _ORGFRAMEID = _ORGFRAMEID;

等價語句:

select * from mt_pb_org o,mt_pb_orgframe f where _orgframeid = _orgframeid(+);

 2.右連線 (right [outer] join)

右外連線就是將右表中的所有資料分別與左表的`每條資料進行連線組合,返回的結果除了內連線的資料外,還有右表中不符合條件的資料,並在左表相應的列中填上null值。

SQL語句如下:

select * from mt_pb_org o right join mt_pb_orgframe on _orgframeid = _orgframeid;

等價語句:

select * from mt_pb_org o,mt_pb_orgframe f where _orgframeid(+) = _orgframeid;

3.全外連線 (full [outer] join)

全外連線就是將左表的所有資料分別與右表的每條資料進行連線組合,返回的結果除了內連線的資料外,還有兩個表中不符合條件的資料,並在左表或者右表的相應列中填上null值。

SQL語句如下:

select * from mt_pb_org o full join mt_pb_orgframe _orgframeid = _orgframeid;

4.交叉連線(cross join)

交叉連線不帶WHERE 子句,它返回被連線的兩個表所有資料行的笛卡爾積,返回到結果集合中的資料行數等於第一個表中符合查詢條件的資料行數乘以第二個表中符合查詢條件的資料行數。

SQL語句如下:

select * from mt_pb_org o cross join mt_pb_orgframe f;

熱門標籤