SQL Decode statement

安稳与你 提交于 2019-12-02 11:07:37

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

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

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