1.decode 写法简介,只能写表达式。
例:decode(表达式,条件1,值1,条件2,值2··· 默认值)
无法满足多条件的写法,比如,我要a-b = 0 且a !=0 用decode没法实现
2.case when 能写多条件
写法一:case 表达式 when 条件1 then 值1
when 条件2 then 值2
····
else 值 end
写法二:case when a-b=0 and a != 0 then 值
when ··· then ···
else 值 end
本文对比了SQL中DECODE函数与CASE WHEN语句的使用方式及适用场景。DECODE仅支持简单的条件判断并返回对应值,不适用于多条件组合;而CASE WHEN则更为灵活,支持复杂的条件组合,能够实现更丰富的业务逻辑。
1.decode 写法简介,只能写表达式。
例:decode(表达式,条件1,值1,条件2,值2··· 默认值)
无法满足多条件的写法,比如,我要a-b = 0 且a !=0 用decode没法实现
2.case when 能写多条件
写法一:case 表达式 when 条件1 then 值1
when 条件2 then 值2
····
else 值 end
写法二:case when a-b=0 and a != 0 then 值
when ··· then ···
else 值 end
8058