SERPland Flugverkehr/Airtraffic Zürich – Auto Direktimport Dänemark – Disneyland Paris – Legoland Deutschland

13Dec/061

CASE expression in Oracle SQL statement


Let's think we write a select statement and would like to DECODE (on Oracle database) on a column:

DECODE(bew.bewart_tid, 'GDL', 'Grenzüberschr. Dienstl. aus EWR Raum' ,bewart.bezeichnung) col_alias

Now you'd like to decode an additional value on the same column. This could result in a not-well-readable DECODE expression.
Better you try to use the CASE expression:

, case when bew.bewart_tid = 'GDL' then 'Grenzüberschr. Dienstl. aus EWR Raum'
when bew.bewart_tid = 'GDLA' then 'Grenzüberschr. Dienstl. aus EWR Raum'
else bewart.bezeichnung
end col_alias

This is a well-formed and well-readable SQL statement.

Related Posts:

Comments (1) Trackbacks (0)
  1. the same as in pl/sql :

    case n
    when 1 then Action1;
    when 2 then Action2;
    when 3 then Action3;
    else ActionOther;
    end case;

    or

    text := case n
    when 1 then one
    when 2 then two

    when 3 then three
    else other
    end case;

    or

    case
    when p = 1 then Action1;
    when r = 2 then Action2;
    when q > 1 then Action3;
    end case;
    exception
    when case_not_found
    then


Leave a comment

No trackbacks yet.