博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nvl, nvl2, nullif
阅读量:2451 次
发布时间:2019-05-10

本文共 2090 字,大约阅读时间需要 6 分钟。

NVL,NVL2,NULLIF三个函数的含义

NULL指的是空值,或者非法值。

NVL (expr1, expr2)->expr1为NULL,返回expr2;不为NULL,返回expr1。注意两者的类型要一致
NVL2 (expr1, expr2, expr3) ->expr1不为NULL,返回expr2;为NULL,返回expr3。expr2和expr3类型不同的话,expr3会转换为expr2的类型
NULLIF (expr1, expr2) ->相等返回NULL,不等返回expr1
nvl2函数的例子
SELECT NVL2(partition_name,segment_name || ':' || partition_name,segment_name)
  FROM user_segments
 WHERE segment_type IN ('TABLE', 'TABLE PARTITION')
   and segment_name NOT IN (SELECT object_name FROM recyclebin bin);
摘自<>中对nullif的解释
----------------quote begin-------------------------------------------------
Purpose
NULLIF compares expr1 and expr2. If they are equal, then the function returns
null. If they are not equal, then the function returns expr1. You cannot specify the
literal NULL for expr1.
If both arguments are numeric datatypes, then Oracle Database determines the
argument with the higher numeric precedence, implicitly converts the other
argument to that datatype, and returns that datatype. If the arguments are not
numeric, then they must be of the same datatype, or Oracle returns an error.
The NULLIF function is logically equivalent to the following CASE expression:
CASE WHEN expr1 = expr 2 THEN NULL ELSE expr1 END
Examples
The following example selects those employees from the sample schema hr who
have changed jobs since they were hired, as indicated by a job_id in the job_
history table different from the current job_id in the employees table:
SELECT e.last_name, NULLIF(e.job_id, j.job_id) "Old Job ID"
  FROM employees e, job_history j
  WHERE e.employee_id = j.employee_id
  ORDER BY last_name;
LAST_NAME Old Job ID
------------------------- ----------
De Haan AD_VP
Hartstein MK_MAN
Kaufling ST_MAN
Kochhar AD_VP
Kochhar AD_VP
Raphaely PU_MAN
Taylor SA_REP
Taylor
Whalen AD_ASST
Whalen
----------------quote begin-------------------------------------------------
上述有误, 应该是“New Job ID”
expr1,expr2除了numeric datatype以外,为其它类型时要求一致,否则会报错
注:在mysql中nullif的函数与oracle中nullif一致

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/94384/viewspace-600291/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/94384/viewspace-600291/

你可能感兴趣的文章
mac命令行将输出写入文件_如何使用命令行将备份,文件和脚本迁移到云中/从云中迁移
查看>>
sql数据库性能指标_SQL Server磁盘性能指标–第2部分–其他重要的磁盘性能指标
查看>>
sql数据库性能指标_SQL Server磁盘性能指标–第1部分–最重要的磁盘性能指标
查看>>
SQL Server复制
查看>>
ssis zip压缩文件_SSIS平面文件与原始文件
查看>>
iif sql_SQL IIF语句概述
查看>>
mekko 教程_Power BI桌面Mekko图表
查看>>
SQL Server数据库快照
查看>>
sql 时态表的意义_SQL Server中的时态表
查看>>
activiti 功能概述_子串功能概述
查看>>
SQL Server中的执行计划
查看>>
power bi 背景图_Power BI桌面脉冲图
查看>>
使用C#脚本扩展Biml
查看>>
exec sql_EXEC SQL概述和示例
查看>>
sql中聚合函数和分组函数_学习SQL:聚合函数
查看>>
索引sql server_维护SQL Server索引
查看>>
sql rank_SQL RANK功能概述
查看>>
保存您SQL执行计划
查看>>
filetable_SQL Server FILETABLE用例
查看>>
ssis组件_SSIS脚本组件概述
查看>>