oracle中any,some,all用法

來源:互聯網
上載者:User
 

平時工作中,很少用any、some、all,今天突然看到這種用法,感覺很不錯,工作中應該能用到;

 

用some,any和all對子查詢中返回的多行結果進行處理。

下面我們來簡單介一下這幾個關鍵詞的含義。   

* Some在此表示滿足其中一個的意義,是用or串起來的比較從句。

* Any也表示滿足其中一個的意義,也是用or串起來的比較從句,區別是any一般用在非“=”的比較關係中,這也很好理解,英文中的否定句中使用any肯定句中使用some,這一點是一樣的。

* All則表示滿足其其中所有的查詢結果的含義,使用and串起來的比較從句。

 

 

Any

帶【any】的巢狀查詢和【some】的巢狀查詢功能是一樣的。早期的SQL僅僅允許使用【any】,後來的版本為了和英語的【any】相區分,引入了【some】,同時還保留了【any】關鍵詞。

any:

select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal >any(select sal from scott.emp where     job='MANAGER');

帶any的查詢過程等價於兩步的執行過程。

    (1)執行“select sal from scott.emp where job='MANAGER'”

 select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal >2975 or sal>2850 or sal>2450;

 

some

some:

select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal =some(select sal from scott.emp where     job='MANAGER');

 

 帶some的巢狀查詢與any的步驟相同。

    (1)子查詢,執行“select sal from scott.emp where job='MANAGER'”,其結果4.22所示。

    (2)父查詢執行下列語句。

    ―――――――――――――――――――――――――――――――――――――

    select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal =2975 or sal=2850 or sal=2450;

 

all

 

all 是查詢還可以是子查詢

如:

 

select name from edit

其中name前省略了all.

name前可以加ALL|DISTINCT

all是所有記錄.

distinct是不重複的。

 

select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal >all(select sal from scott.emp where     job='MANAGER');

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.