久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

Oracle中集合查詢的示例分析

共計(jì) 1587 個(gè)字符,預(yù)計(jì)需要花費(fèi) 4 分鐘才能閱讀完成。

這篇文章主要介紹了 Oracle 中集合查詢的示例分析,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓丸趣 TV 小編帶著大家一起了解一下。

使用并集運(yùn)算,查詢 20 號(hào)部門或 30 號(hào)部門的員工信息

select * from emp where deptno = 20
union
select * from emp where deptno = 30;

注意:

union:二個(gè)集合中,如果都有相同的,取其一

union all:二個(gè)集合中,如果都有相同的,都取

使用 set time/timing on,打開時(shí)間的開關(guān)

set time on;
set time off;

使用 set time/timing off,關(guān)閉時(shí)間的開關(guān)

set timing on;
set timint off;

使用交集運(yùn)算 [intersect],查詢工資在 1000-2000 和 1500-2500 之間的員工信息(方式一)

select * from emp where sal between 1000 and 2000
intersect
select * from emp where sal between 1500 and 2500;

用 where 行過(guò)濾,查詢工資在 1000-2000 和 1500-2500 之間的員工信息(方式二)

select * 
from emp
where (sal between 1000 and 2000) and (sal between 1500 and 2500);

使用差集運(yùn)算 [minus],查詢工資在 1000-2000,但不在 1500-2500 之間的員工信息(方式一)

select * from emp where sal between 1000 and 2000
minus
select * from emp where sal between 1500 and 2500;

使用 where 行過(guò)濾,查詢工資在 1000-2000,但不在 1500-2500 之間的員工信息(方式二)

select * 
from emp 
where (sal between 1000 and 2000) and (sal not between 1500 and 2500);

集合查詢的細(xì)節(jié):

1)集合操作時(shí),必須確保集合列數(shù)是相等的

select empno,ename,sal,comm from emp where deptno = 20

union

select empno,ename,sal from emp where deptno = 30; 錯(cuò)

2)集合操作時(shí),必須確保集合列類型對(duì)應(yīng)相同

select empno,ename,sal,comm from emp where deptno = 20

union

select empno,ename,sal,hiredate from emp where deptno = 30; 錯(cuò)

3)A union B union C = C union B union A

select * from emp where deptno = 10

union

select * from emp where deptno = 20

union

select * from emp where deptno = 30;

4)當(dāng)多個(gè)集合操作時(shí),結(jié)果的列名由第一個(gè)集合列名決定

select empno  編號(hào) ,ename  姓名 ,sal  薪水  from emp where deptno = 20
union
select empno,ename,sal from emp where deptno = 10;

當(dāng)多表查詢,子查詢,集合查詢都能完成同樣任務(wù)時(shí),按如下優(yōu)化方案選擇:

多表查詢 - 子查詢 - 集合查詢

感謝你能夠認(rèn)真閱讀完這篇文章,希望丸趣 TV 小編分享的“Oracle 中集合查詢的示例分析”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持丸趣 TV,關(guān)注丸趣 TV 行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!

正文完
 
丸趣
版權(quán)聲明:本站原創(chuàng)文章,由 丸趣 2023-07-24發(fā)表,共計(jì)1587字。
轉(zhuǎn)載說(shuō)明:除特殊說(shuō)明外本站除技術(shù)相關(guān)以外文章皆由網(wǎng)絡(luò)搜集發(fā)布,轉(zhuǎn)載請(qǐng)注明出處。
評(píng)論(沒有評(píng)論)
主站蜘蛛池模板: 常山县| 托克逊县| 德令哈市| 浏阳市| 湘潭市| 高雄市| 乳山市| 都匀市| 屯昌县| 卢氏县| 武乡县| 滦平县| 三都| 日喀则市| 墨竹工卡县| 澜沧| 昂仁县| 称多县| 河曲县| 文安县| 临西县| 临朐县| 甘南县| 彭阳县| 新河县| 赤水市| 横峰县| 龙陵县| 开原市| 老河口市| 延寿县| 天等县| 榆林市| 克山县| 杭州市| 通辽市| 肃宁县| 太白县| 同心县| 始兴县| 林州市|