问题
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