nvl, nvl2, nullif
NVL,NVL2,NULLIF三個函式的含義
NULL指的是空值,或者非法值。
NVL (expr1, expr2)->expr1為NULL,返回expr2;不為NULL,返回expr1。注意兩者的型別要一致
NVL2 (expr1, expr2, expr3) ->expr1不為NULL,返回expr2;為NULL,返回expr3。expr2和expr3型別不同的話,expr3會轉換為expr2的型別
NULLIF (expr1, expr2) ->相等返回NULL,不等返回expr1
nvl2函式的例子
SELECT NVL2(partition_name,segment_name || ':' || partition_name,segment_name)
FROM user_segments
WHERE segment_type IN ('TABLE', 'TABLE PARTITION')
and segment_name NOT IN (SELECT object_name FROM recyclebin bin);
摘自<
----------------quote begin-------------------------------------------------
Purpose
NULLIF compares expr1 and expr2. If they are equal, then the function returns
null. If they are not equal, then the function returns expr1. You cannot specify the
literal NULL for expr1.
If both arguments are numeric datatypes, then Oracle Database determines the
argument with the higher numeric precedence, implicitly converts the other
argument to that datatype, and returns that datatype. If the arguments are not
numeric, then they must be of the same datatype, or Oracle returns an error.
The NULLIF function is logically equivalent to the following CASE expression:
CASE WHEN expr1 = expr 2 THEN NULL ELSE expr1 END
Examples
The following example selects those employees from the sample schema hr who
have changed jobs since they were hired, as indicated by a job_id in the job_
history table different from the current job_id in the employees table:
SELECT e.last_name, NULLIF(e.job_id, j.job_id) "Old Job ID"
FROM employees e, job_history j
WHERE e.employee_id = j.employee_id
ORDER BY last_name;
LAST_NAME Old Job ID
------------------------- ----------
De Haan AD_VP
Hartstein MK_MAN
Kaufling ST_MAN
Kochhar AD_VP
Kochhar AD_VP
Raphaely PU_MAN
Taylor SA_REP
Taylor
Whalen AD_ASST
Whalen
----------------quote begin-------------------------------------------------
上述有誤, 應該是“New Job ID”
expr1,expr2除了numeric datatype以外,為其它型別時要求一致,否則會報錯
注:在mysql中nullif的函式與oracle中nullif一致
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/94384/viewspace-600291/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [Developer] NVL,NVL2,NULLIF,COALESCE,DECADE,CASEDeveloperNull
- nvl、nvl2與nullif函式用法區別Null函式
- to_date、to_char及格式化大小寫 nvl nvl2 nullifNull
- Oracle-nvl和nvl2函式Oracle函式
- 【函式】oracle nvl2 函式函式Oracle
- 對遠端表使用NVL2的bug
- 新學一個函式nvl2(a,b,c)函式
- Oracle中處理空值的函式nvl-nvl2-lnnvl-nullif的用法Oracle函式Null
- nullifNull
- 【Oracle的NVL函式用法】Oracle函式
- MySQL 的IFNULL()、ISNULL()和NULLIF()函式MySqlNull函式
- Oracle關於nvl的一個BugOracle
- sql中的nvl是幹嘛的?SQL
- oracle 使用nullif解決除數為零的問題OracleNull
- [20200213]函式nullif使用.txt函式Null
- [20170424]函式COALESCE優於NVL.txt函式
- [20170516]nvl與非NULL約束.txtNull
- [20170503]]函式COALESCE優於NVL 2.txt函式
- [20170516]nvl與非NULL約束2.txtNull
- Oracle-空值null和數字相加的問題-nvl函式OracleNull函式
- 10g與11g在處理 >= nvl(:b1,0) and
- 用decode和nvl處理null值時需要注意的地方Null
- Oracle update set欄位=nvl(n,0)還報《ORA-01407:無法更新欄位為NULL》原因分析和解決OracleNull