介绍:
decode函数主要根据条件判断得出你想要的结果,跟 case when 得出的结果类似。
用法:
decode(字段,判断值1,返回值1,判断值2,返回值2,判断值3,返回值3...判断值n,返回值n,缺省值)
当字段等于判断值1时则返回返回值1,
当字段等于判断值2时则返回返回值2,
......
否则返回缺省值
类似于:
case when 字段=判断值1 then 返回值1
when 字段=判断值2 then 返回值2
else 缺省值
END
例如:
select decode(mm,1,1,null) from day
当天为1时则返回1,否则返回null
本文章为原创文章,未经博主同意,不得转载。
原文:http://www.cnblogs.com/kim99/p/6383277.html