標籤: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使用