oracle nvl,nvl2,coalesce几个函数的区别
1.nvl(exp1,exp2)
NVL
lets you replace null (returned as a blank) with a string in the results of a query. If expr1
is null, then NVL
returns expr2
. If expr1
is not null, then NVL
returnsexpr1
.
该函数是处理表达式中的空值:假设表达式exp1是空值,则该函数返回表达式exp2的值,
假设表达式exp1没有是空值,则该函数返回表达式exp1的值。
2.nvl2(exp1,exp2,exp3)
NVL2
lets you determine the value returned by a query based on whether a specified expression is null or not null. If expr1
is not null, then NVL2
returns expr2
. Ifexpr1
is null, then NVL2
returns expr3
.
该函数决意exp1离去是空值和非空值时返回哪个表达式:
假设exp1为空值,则返回exp3
假设exp1非空,返回exp2。
3.coalesce(exp1,exp2,.....)
COALESCE
returns the first non-null expr
in the expression list. You must specify at least two expressions. If all occurrences of expr
evaluate to null, then the function returns null.
该函数正在括号里全数的表达式中返回第一个非空值,假设都是空值,则返回空值,表达式最少是两个。