在oracle中可以看到decode函数,使用方法如下:
decode(条件,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值)的理解如下:
if (条件==值1)
then
return(翻译值1)
elsif (条件==值2)
then
return(翻译值2)
......
elsif (条件==值n)
then
return(翻译值n)
else
return(缺省值)
end if
而在mysql中用到case when来替代decode
case 条件
when 值1 then 翻译值1
when 值2 then 翻译值2
when 值3 then 翻译值3
else other end
本文介绍了Oracle数据库中的Decode函数及MySQL中的Case When语句的使用方法。Decode函数类似于条件判断,通过比较条件与给定值来返回相应的翻译值;而Case When则是在MySQL中实现相同功能的方式。
305

被折叠的 条评论
为什么被折叠?



