Oracle函数-NULLIF(CASE函数的简化形式)

CASE函数经常看到,NULLIF不怎么用到。今天学习一下。

--------------------------------------------------------------------------------------------------------------------------------

NULLIF
Syntax
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 data types, then Oracle Database determines the
argument with the higher numeric precedence, implicitly converts the other argument
to that data type, and returns that data type. If the arguments are not numeric, then
they must be of the same data type, or Oracle returns an error.
The NULLIF function is logically equivalent to the following CASE expression:
CASE WHEN expr1 = expr2 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(j.job_id, e.job_id) "Old Job ID"
FROM employees e, job_history j
WHERE e.employee_id = j.employee_id
ORDER BY last_name, "Old Job ID";
LAST_NAME Old Job ID
------------------------- ----------
De Haan IT_PROG
Hartstein MK_REP
Kaufling ST_CLERK
Kochhar AC_ACCOUNT
Kochhar AC_MGR
Raphaely ST_CLERK
Taylor SA_MAN
Taylor
Whalen AC_ACCOUNT
Whalen

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值