Oracle 中NVL的用法及含义
2014-09-10 14:29
253 查看
Oracle PL/SQL中的一个函数。
格式为:NVL( string1, replace_with)
功能:如果string1为NULL,则NVL函数返回replace_with的值,否则返回string1的值,如果两个参数都为NULL ,则返回NULL。
注意事项:string1和replace_with必须为同一数据类型,除非显式的使用TO_CHAR函数进行类型转换。
例:NVL(TO_CHAR(numeric_column), 'some string') 其中numeric_column代指某个数字类型的值。
例:nvl(yanlei777,0) > 0
NVL(yanlei777, 0) 的意思是 如果 yanlei777 是NULL, 则取 0值
通过查询获得某个字段的合计值,如果这个值为null将给出一个预设的默认值
例如:
select nvl(sum(t.dwxhl),1)
from tb_jhde t
就表示如果sum(t.dwxhl) = NULL 就返回 1
另一个有关的有用方法
declare i integer
select nvl(sum(t.dwxhl),1) into i from tb_jhde t where zydm=-1这样就可以把获得的合计值存储到变量
i中,如果查询的值为null就把它的值设置为默认的1
orcale中:
select nvl(rulescore,0) from zwjc_graderule where rulecode='FWTD';
如果记录中不存在rulecode ='FWTD'的数据.则查不出数据.
select nvl(rulescore,0) into rule_score from zwjc_graderule where rulecode='FWTD';会报查不到数据的错
select nvl(sum(rulescore),0) from zwjc_graderule where rulecode='FWTD';
如果记录中不存在rulecode ='FWTD'的数据.还是可以得到一行列名为nvl(rulescore,0),值为0的数据.
select nvl(sum(rulescore),0) into rule_score from zwjc_graderule where rulecode='FWTD'; 不会报错
格式为:NVL( string1, replace_with)
功能:如果string1为NULL,则NVL函数返回replace_with的值,否则返回string1的值,如果两个参数都为NULL ,则返回NULL。
注意事项:string1和replace_with必须为同一数据类型,除非显式的使用TO_CHAR函数进行类型转换。
例:NVL(TO_CHAR(numeric_column), 'some string') 其中numeric_column代指某个数字类型的值。
例:nvl(yanlei777,0) > 0
NVL(yanlei777, 0) 的意思是 如果 yanlei777 是NULL, 则取 0值
通过查询获得某个字段的合计值,如果这个值为null将给出一个预设的默认值
例如:
select nvl(sum(t.dwxhl),1)
from tb_jhde t
就表示如果sum(t.dwxhl) = NULL 就返回 1
另一个有关的有用方法
declare i integer
select nvl(sum(t.dwxhl),1) into i from tb_jhde t where zydm=-1这样就可以把获得的合计值存储到变量
i中,如果查询的值为null就把它的值设置为默认的1
orcale中:
select nvl(rulescore,0) from zwjc_graderule where rulecode='FWTD';
如果记录中不存在rulecode ='FWTD'的数据.则查不出数据.
select nvl(rulescore,0) into rule_score from zwjc_graderule where rulecode='FWTD';会报查不到数据的错
select nvl(sum(rulescore),0) from zwjc_graderule where rulecode='FWTD';
如果记录中不存在rulecode ='FWTD'的数据.还是可以得到一行列名为nvl(rulescore,0),值为0的数据.
select nvl(sum(rulescore),0) into rule_score from zwjc_graderule where rulecode='FWTD'; 不会报错
相关文章推荐
- Oracle --nvl(),CASE WHEN 用法介绍
- Oracle中集中对于NULL操作的函数NVL,NVL2,以及COALESCE的用法
- Oracle中的INSTR,NVL和SUBSTR函数的用法代码实例
- Oracle 中 nvl、nvl2、nullif、coalesce、decode 函数的用法详解
- Mysql中ifNull()/if()/case when用法和Oracle中nvl()/nvl2()/decode()的用法
- oracle nvl()用法
- Oracle中NVL、NVL2、DECODE函数的用法
- Oracle中的INSTR,NVL和SUBSTR函数的用法详解
- Oracle中处理空值的函数nvl-nvl2-lnnvl-nullif的用法
- Oracle decode和nvl 函数的用法及区别?
- oracle中的NVL和NVL2及NULLIF再及decode函数用法总结
- Oracle中NVL、NVL2、DECODE函数的用法
- 【oracle】DECODE ,NVL,NVL2的用法
- Oracle 中 nvl、nvl2、nullif、coalesce、decode 函数的用法详解
- Oracle中decode函数用法含义
- oracle中的nvl 、nvl2、decode、case when 函数的用法
- oracle nvl,having的用法
- Oracle中decode函数用法含义
- Oracle 中 nvl、nvl2、nullif、coalesce、decode 函数的用法详解
- oracle NVL、NVL2,、NULLIF、COALESCE函数的用法