question

BI DWH BALA avatar image
BI DWH BALA asked

Switch - equivalent statement in Oracle?

Hi,

I have a column Gender, which contains values either M or F. While running a query, I want to display 'Male' for M and 'Female' for F.

Generally in programming languages we have Switch statement. Is there any similar functionality available in Oracle?

Regards, BI DWH BALA

oracleswitchcase-expression
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Christian13467 avatar image
Christian13467 answered

There are two them.

DECODE
This is for SQL Statements only.

CASE
This works in SQL and PL/SQL. The grammar is a bit different.

The links show you the definition in oracle documentation.

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

KillerDBA avatar image KillerDBA commented ·
FYI - CASE is also supported by SQL Server and DB/2. I think it's part of the standard. If you're trying to do something "portable," or which will be understood by people with SQL experience but without Oracle backgrounds, I'd stick to CASE. I'm pretty sure DECODE is not standard.
1 Like 1 ·
BI DWH BALA avatar image BI DWH BALA commented ·
I used Decode in my scenario. Thank you very much Christian.
0 Likes 0 ·
Christian13467 avatar image Christian13467 commented ·
Yes, CASE was introduced by oracle to be more standard conform. CASE is more to write but its more powerful than decode.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.