Oracle decode和nvl 函数的用法及区别?
2015-01-08 15:48
645 查看
Decode
decode(条件,值1,翻译值1,值2,翻译值2,...,缺省值) 该函数与程序中的 If...else if...else 意义一样NVL
格式:NVL( string1, replace_with)功能:如果string1为NULL,则NVL函数返回replace_with的值,否则返回string1的值,如果两个参数都为NULL
,则返回NULL。
注意事项:string1和replace_with必须为同一数据类型,除非显式的使用TO_CHAR函数进行类型转换。
select nvl(sum(t.dwxhl),1) from tb_jhde t 就表示如果sum(t.dwxhl) = NULL 就返回 1
Oracle在NVL函数的功能上扩展,提供了NVL2函数
NVL2
nvl2 (E1, E2, E3) 的功能为:如果E1为NULL,则函数返回E3,否则返回E2结合
Decode 和 NVL等函数 常常结合使用,例如
select
monthid,decode(nvl(sale,6000),6000,'NG','OK') from output
sign()函数根据某个值是0、正数还是负数,分别返回0、1、-1,
如果取较小值就是select
monthid,decode(sign(sale-6000),-1,sale,6000) from output,即达到取较小值的目的。
相关文章推荐
- Oracle 中 nvl、nvl2、nullif、coalesce、decode 函数的用法详解
- Oracle 中 nvl、nvl2、nullif、coalesce、decode 函数的用法详解
- oracle中的nvl 、nvl2、decode、case when 函数的用法
- oracle函数之case和decode的用法区别及性能比较
- oracle函数之case和decode的用法区别及性能比较
- oracle中decode()和nvl()函数的用法
- Oracle 中 nvl、nvl2、nullif、coalesce、decode 函数的用法详解
- [Oracle] decode 函数及其用法
- oracle decode.oracle 函数用法之decode
- DECODE 函数的用法(oracle)
- Oracle 中 decode 函数用法
- [Oracle] decode 函数及其用法
- oracle NVL、NVL2,、NULLIF、COALESCE函数的用法
- Oracle 中 decode 函数用法
- Oracle中nvl和nvl2这两个函数的区别
- Oracle 中 decode 函数用法
- oracle 中的 decode()、nvl()、sign()函数详解
- Oracle中集中对于NULL操作的函数NVL,NVL2,以及COALESCE的用法
- oracle 截取函数 trunc (直接截取不做进位处理)、round(截取时要进位) 的用法与区别
- oracle里面如何写case语句及decode and sign 函数用法