oracle中coalesce case decode函数的使用方法

2024-10-24 07:28:50

1、coalesce函数语法coalesce(exp1,exp2,exp3....);它的使用是找到不为空的表达式,并返回值,如果所有的表达都为空则返回空

oracle中coalesce case decode函数的使用方法

2、case函数语法case exp1 when exp2 then exp3 when exp4 then exp5.......when .....then else exp end; 它的使用是判断表达式exp1与exp2是否相等如果相等则返回exp3,如果不相等则继续向下匹配。

oracle中coalesce case decode函数的使用方法oracle中coalesce case decode函数的使用方法

3、但有一点需要注意的是如果case函数中所有case条件与when条件都不匹配,那么所有的值都会使用else表达式的值。

oracle中coalesce case decode函数的使用方法

4、decode函数语法decode(exp1,exp2,exp3,default);它的使用是exp1与exp2相比较如果相等嬴猹缥犴则返回exp3的值如果不相等则返回default默认值。这个函数的使用其实是case函数的简化。

oracle中coalesce case decode函数的使用方法oracle中coalesce case decode函数的使用方法

5、对于decode函数有一点需要注意的是如果没有default默认值则返回空如下图

oracle中coalesce case decode函数的使用方法
猜你喜欢