Suppose I have a table where I have a field which can have to values: "enabled" and "disabled". Suppose want my query to output "unblocked" instead of "enabled" and "blocked" instead of "disabled". How to do that in Oracle?
1 Answer
Either use the SQL standard way of CASE WHEN ...
as ypercybe suggested in the comments or for more neat result, DECODE
function:
DECODE(fieldref, 'enabled', 'unblocked', 'disabled', 'blocked')
-
1I think DECODE is less readable. So I decided to use CASE - it seams more understandable for the person who will join the team to maintain this code. But anyway, thanks, it is very interesting to know about this possibility. Commented Jul 14, 2014 at 16:07
CASE WHEN ...