-1

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?

Mario S
  • 11,715
  • 24
  • 39
  • 47

3 Answers3

0
select decode(columnA,'dog','B','cat','T','not a dog or cat')
from dual
StevieG
  • 8,639
  • 23
  • 31
  • 1
    decode accepts an unlimited number of pairs so you can do `decode(columnA,'Dog','B', 'Cat', 'T', 'not a dog or cat')` without needing to nest decodes. – DazzaL Dec 04 '12 at 16:39
  • @StevieG I am not sure why you see the need to have the `decode` inside the `decode`. – Anjan Biswas Dec 04 '12 at 20:16
0

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 ...
wolφi
  • 8,091
  • 2
  • 35
  • 64
-1
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')
Anjan Biswas
  • 7,746
  • 5
  • 47
  • 77
  • Well to the -1 voter - Please go through how to use a decode function - http://www.techonthenet.com/oracle/functions/decode.php – Anjan Biswas Dec 04 '12 at 20:14