在SQL中使用DECODE函数进行解码操作
发布时间
阅读量:
阅读量
业务需求:在ptr.offdate字段未填写的情况下,转正日期应依据stu.preformaltime进行计算;若ptr.offdate字段已填写,则转正日期应以offdate作为计算依据。
采用decode()函数表达即为decode(ptr.offdate,null,stu.preformaltime,ptr.offdate) offdate
其含义为:
if (ptr.offdate==null)
then
return(stu.preformaltime)
elsif (ptr.offdate!=null)
then
return(ptr.offdate)
关于decode()函数的简要说明:
核心功能:将查询所得结果转换为其他形式的表达(以下通过实例进一步说明);
使用方式:
Select decode(columnname,值1,翻译值1,值2,翻译值2,…值n,翻译值n,缺省值)
From tablename
Where …
其中columnname表示从表中所定义的列中提取的数据,
·意义解析:
decode(条件,值1,翻译值1,值2,翻译值2,…值n,翻译值n,缺省值)的含义如下:
if (条件==值1)
then
return(翻译值1)
elsif (条件==值2)
then
return
全部评论 (0)
还没有任何评论哟~
