oracle中decode的使用

您所在的位置:网站首页 oracle中decode函数在pgsql中使用 oracle中decode的使用

oracle中decode的使用

2024-07-17 22:34| 来源: 网络整理| 查看: 265

含义解释:decode(条件,值1,返回值1,值2,返回值2,…值n,返回值n,缺省值)

例如:

select decode(1,1,'第一个',2,'第二个',3,'第三个','没有') from dual

返回:第一个

其作用相当于case...when...

select case 1 when 1 then '第一个' when 2 then '第二个' when 3 then '第三个' else '没有' end results from dual

decode 与 case..when..区别:

1.DECODE 只有Oracle 才有,其它数据库不支持; 2.CASE WHEN的用法, Oracle、SQL Server、 MySQL 都支持; 3.DECODE 只能用做相等判断,但是可以配合sign函数进行大于,小于,等于的判断,CASE when可用于=,>=,



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3