SQL Decode statement

隐身守侯 提交于 2019-12-20 06:08:56

问题


I am trying to use a SQL Decode statement to Decode (D.code ,2,'Resident',else,'Business') Description, Is there a way to identify everything else in a decode statement?


回答1:


yes, there is:

decode ( <condition>, <test expr #1>, <result #1>, ..., <test expr #n>, <result #n>, <fallback result>);

however, in standard sql you would use

case <condition>
    when <test expr #1> then <result #1>
    ...
    when <test expr #n> then <result #n>
    else                     <fallback result>
end



回答2:


You have the basic syntax correct except you don't use the 'else' in a DECODE function. Inside the parentheses is first the thing to decode, then the code/description pairs, then finally, the optional default (else) value.

Here is a sample of one that I use:

DECODE(status,'A','Approved','D','Declined','I','Counter Offer','Other')

Good luck,

Marvin



来源:https://stackoverflow.com/questions/18213972/sql-decode-statement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!