【SQL查询】查询结果翻译成其他值_decode

decode()函数简介:

主要作用:将查询结果翻译成其他值(即以其他形式表现出来,以下举例说明);

使用方法:

Select decode(columnname,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值)

From talbename

Where …

其中columnname为要选择的table中所定义的column,

·含义解释:

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

注:其中缺省值可以是你要选择的column name 本身,也可以是你想定义的其他值,比如Other等;

举例说明:

现定义一table名为output,其中定义两个column分别为monthid(var型)和sale(number型),若sale值=1000时翻译为D,=2000时翻译为C,=3000时翻译为B,=4000时翻译为A,如是其他值则翻译为Other;

SQL如下:

Select monthid , decode (sale,1000,'D',2000,'C',3000,'B',4000,'A',’Other’) sale from output

摘自:https://www.cnblogs.com/freespider/archive/2010/08/09/1795977.html

posted @ 2017-11-30 13:58  坏脾气  阅读(2289)  评论(0编辑  收藏  举报