Mysql中ifNull()/if()/case when用法和Oracle中nvl()/nvl2()/decode()的用法
2018-04-04 10:25
1116 查看
一、Mysql中ifNull()/if()/case when的用法
IFNULL函数的用法:
IFNULL(expr1,expr2),表示若expr1为NULL,则返回expr2,否则返回expr1。
IF函数的用法:
IF(expr1,expr2,expr3),表示若expr1为TRUE(expr1<>0且expr1<>NULL),则返回expr2,否则返回expr3。
CASE WHEN函数的用法:
CASE WHEN condition1 THEN result1 [WHEN condition2 THEN result2 …] [ELSE resultN] END,表示若condition1为TRUE,则返回result1 ,否则若condition2为true则返回result2…,若均不满足则返回resultN。
二、Oracle中nvl()/nvl2()/decode()的用法
NVL函数的用法:
NVL(expr1,expr2),表示若expr1为NULL,则返回expr2,否则返回expr1。
NVL2函数的用法:
NVL2(expr1,expr2,expr3),表示若expr1不为NULL,则返回expr2,否则返回expr3。
DECODE函数的用法:
DECODE(value,if1,then1,if2,then2,if3,then3,……,else),表示若value等于if1,则返回then1,否则若等于if2则返回then2,……,若均不满足则返回else。
三:总结
通过比较,可以发现:
ifNull(exp1,exp2)类似于nvl(exp1,exp2);
if(exp1,exp2,exp3)类似于nvl2(exp1,exp2,exp3);
CASE WHEN 类似于DECODE()。
IFNULL函数的用法:
IFNULL(expr1,expr2),表示若expr1为NULL,则返回expr2,否则返回expr1。
IF函数的用法:
IF(expr1,expr2,expr3),表示若expr1为TRUE(expr1<>0且expr1<>NULL),则返回expr2,否则返回expr3。
CASE WHEN函数的用法:
CASE WHEN condition1 THEN result1 [WHEN condition2 THEN result2 …] [ELSE resultN] END,表示若condition1为TRUE,则返回result1 ,否则若condition2为true则返回result2…,若均不满足则返回resultN。
二、Oracle中nvl()/nvl2()/decode()的用法
NVL函数的用法:
NVL(expr1,expr2),表示若expr1为NULL,则返回expr2,否则返回expr1。
NVL2函数的用法:
NVL2(expr1,expr2,expr3),表示若expr1不为NULL,则返回expr2,否则返回expr3。
DECODE函数的用法:
DECODE(value,if1,then1,if2,then2,if3,then3,……,else),表示若value等于if1,则返回then1,否则若等于if2则返回then2,……,若均不满足则返回else。
三:总结
通过比较,可以发现:
ifNull(exp1,exp2)类似于nvl(exp1,exp2);
if(exp1,exp2,exp3)类似于nvl2(exp1,exp2,exp3);
CASE WHEN 类似于DECODE()。
相关文章推荐
- Mysql中ifNull()/if()/case when用法和Oracle中nvl()/nvl2()/decode()的用法及其比较
- oracle case when简单用法 IF-THEN-ELSE
- ORACLE 中 DECODE 与 CASE WHEN THEN 用法
- case when then end与decode 介绍(附带 sign(),nvl(),ifnull())
- Oracle中case when和decode的用法
- oracle case when及decode的用法
- Oracle 中 nvl、nvl2、nullif、coalesce、decode 函数的用法详解
- 【oracle】DECODE ,NVL,NVL2的用法
- oracle中的nvl 、nvl2、decode、case when 函数的用法
- Oracle 常用函数:nvl/nullif/case when/wm_concat/replace
- NVL NVL2 NULLIF DECODE CASE
- Mysql-通过case..when实现oracle decode()函数进行多值多结果判断
- NVL NVL2 NULLIF DECODE CASE
- SQL通用函数-nvl-nvl2 -nvlif-nullif-coalesce-decode-case
- Oracle常用函数:nvl/nullif/case when/wm_concat/replace
- mysql中case、when、if、then的用法
- 参数返回Oracle 常用函数:nvl/nullif/case when/wm_concat/replace
- mysql的IFNULL、IF、CASE...WHEN...THEN...函数的使用讲解
- oracle一些重要函数:nvl, nvl2, nullif,COALESCE,decode,case
- Oracle 中 nvl、nvl2、nullif、coalesce、decode 函数的用法详解