1.nvl(exp1,exp2)
NVL
letsyou replace null (returned as a blank) with a string in the resultsof a query. If expr1
isnull, then NVL
returns expr2
.If expr1
isnot null, then NVL
returnsexpr1
.
该函数是处理表达式中的空值:如果表达式exp1是空值,则该函数返回表达式exp2的值,
如果表达式exp1不是空值,则该函数返回表达式exp1的值。
2.nvl2(exp1,exp2,exp3)
NVL2
letsyou determine the value returned by a query based on whether aspecified expression is null or not null.If expr1
isnot null,then NVL2
returns expr2
.Ifexpr1
isnull, then NVL2
returns expr3
.
该函数决定exp1分别是空值和非空值时返回哪个表达式:
如果exp1为空值,则返回exp3
如果exp1非空,返回exp2。
3.coalesce(exp1,exp2,.....)
COALESCE
returnsthe first non-null expr
inthe expression list. You must specify at least two expressions. Ifall occurrences of expr
evaluateto null, then the function returns null.
该函数在括号里所有的表达式中返回第一个非空值,如果都是空值,则返回空值,表达式至少是两个。
例子:
这个例子里面,是显示产品的售价,在标价(list_price)的基础上打九折,如果标价为空,则显示最低价(min_price),如果标价和最低价都为空,则显示5。
4.补充一下最后一个nullif
nullif(expression1,expression2) 如果两个表达式相等,则返回null,如果不相等,则返回expression1