0

I have a column in a table which usually is filled with 10 or 11 values. I need to make a report and need to transform this 10 value into 'Class1' and 11 into 'Class2' texts and null in any other case.

I made it in the past but forget to save it as a snippet.

A.B.Cade
  • 16,735
  • 1
  • 37
  • 53
Jorge Vega Sánchez
  • 7,430
  • 14
  • 55
  • 77
  • can you give an input/output example of what you want? You want to change the number 10 into the string 'Class1'? – tbone Jan 24 '13 at 11:50

2 Answers2

1

Using case is probably the cleanest solution:

select case my_column
    when 10 then 'Class1'
    when 11 then 'Class2'
    else null
    end
from my_table;

Although having said that, having the text equivalent stored in a table is probably more reliable generally, so you can just join to it.

Alex Poole
  • 183,384
  • 11
  • 179
  • 318
  • Also vaguely related, or at least interesting: [Are a CASE statement and a DECODE equivalent?](http://stackoverflow.com/q/13712763/266304) – Alex Poole Jan 24 '13 at 12:12
0

You can use REPLACE, or DECODE and NVL for the null value, or a CASE.

Plouf
  • 627
  • 3
  • 7
  • But I wonder what keywords you try when looking up on the internet for not finding this. Because even *oracke substitue string* redirects directly to the replace function. – Plouf Jan 24 '13 at 11:34