nvl函数
来源:互联网 发布:软件使用授权书模板 编辑:程序博客网 时间:2024/05/22 06:58
NVL函数 Oracle/PLSQL中的一个函数
格式为:
NVL( string1, replace_with)
功能:如果string1为NULL,则NVL函数返回replace_with的值,否则返回string1的值。
引申一下,此NVL的作用与SQLserver 中的 ISNULL( string1, replace_with) 一样。
注意事项: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
oracle中:
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的扩展-NVL2
Oracle在NVL函数的功能上扩展,提供了NVL2函数。
NVL2(E1, E2, E3)的功能为:如果E1为NULL,则函数返回E3,若E1不为null,则返回E2。
- nvl函数
- NVL()函数
- NVL()函数
- Nvl函数
- nvl函数
- nvl函数
- nvl函数
- nvl函数
- nvl函数
- nvl()函数
- nvl函数
- nvl函数
- NVL函数的使用
- Oracle的Nvl函数
- Oracle Nvl函数
- Oracle NVL函数
- Oracle的nvl函数
- Oracle的Nvl函数
- 计算几何模板
- MFC树控件节点后加图标实现
- GCC介绍
- mongoDB命令
- 关于ociuldr数据导出工具的使用说明
- nvl函数
- ACM的小技巧
- vc try catch捕捉所有异常的问题
- if条件里有两个 或 (||) 符号
- 单元测试与main前运行函数__attribute__((constructor))关键字
- C# Dictionary序列化/反序列化
- ReportViewer 嵌套子报表
- K.Teamwork Brings Profits! 典型的dfs搜索
- 在操作数据库时候出现 sqlite3_open_v2("/data/data/xxx/databases/xxx.db", &handle, 6)failed