Oracle比較函數GREATEST和LEAST使用

來源:互聯網
上載者:User

標籤:oracle   grestest   least函數   

http://docs.oracle.com/cd/E11882_01/server.112/e41084/functions069.htm#i77473

http://docs.oracle.com/cd/E11882_01/server.112/e41084/functions087.htm#i77700

這兩個函數是是一對相反的函數,文法分別為:

650) this.width=650;" alt="Description of least.gif follows" src="http://docs.oracle.com/cd/E11882_01/server.112/e41084/img/least.gif" width="220" height="58" />

650) this.width=650;" alt="Description of greatest.gif follows" src="http://docs.oracle.com/cd/E11882_01/server.112/e41084/img/greatest.gif" width="244" height="58" />

他們都通過第一個expr的字元類型確定傳回值的資料類型。如果第一個運算式是數值型的,則根據數值優先的原則,函數會隱式的將後續的表達是轉換為數實值型別。

 

範例:

SQL> select least(‘china‘,‘england‘,‘american‘,‘russia‘)  country from dual;COUNTRY------------------------american SQL> select greatest(‘china‘,‘england‘,‘american‘,‘russia‘)  country from dual;COUNTRY------------------russia
SQL> select least(1,‘england‘,‘russia‘)  country from dual;select least(1,‘england‘,‘russia‘)  country from dual               *ERROR at line 1:ORA-01722: invalid number

報錯出現,說明當我指定數實值型別時,後續的運算式都被轉化為數值型了

SQL> select least(1,3.14159,0.1415926)  country from dual;   COUNTRY----------  .1415926SQL> select greatest(1,3.14159,0.1415926)  country from dual;   COUNTRY----------   3.14159

 

SQL> select least(‘china‘,‘england‘,2,1)  country from dual;

COU
---
1

這裡可以看到這裡後續的數值被轉化為字元類型了。

本文出自 “LinuxOracle” 部落格,請務必保留此出處http://onlinekof2001.blog.51cto.com/3106724/1611811

Oracle比較函數GREATEST和LEAST使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.