I made a query and my output has columA. In column A the potential data is Dog or Cat,
if the Output is:
- Dog then I want it to be shown as B
- Cat I want it to be shown as T.
How can I do this in Toad for Oracle using a SQL Query?
I made a query and my output has columA. In column A the potential data is Dog or Cat,
if the Output is:
How can I do this in Toad for Oracle using a SQL Query?
select decode(columnA,'dog','B','cat','T','not a dog or cat')
from dual
DECODE
is universally used in the Oracle world, but I'd use the CASE
statement, because it is much more readable:
SELECT CASE myinput
WHEN 'Dog' THEN 'B'
WHEN 'Cat' THEN 'T'
ELSE '?'
END myoutput
FROM ...
select decode(columnA,'Dog', 'B','Cat', 'T', 'None') from dual;
Here is how the DECODE function works
DECODE([If ColumnA is] 'Dog' [then] 'B' [elsif] 'Cat' [then] 'T' ..... [else] 'None')