0 votes
in Oracle by
Where do you use DECODE and CASE Statements?

1 Answer

0 votes
by
Both these statements Decode and Case will work similar to the if-then-else statement and also they are the alternatives for each of them. These functions are used in Oracle for data value transformation.

Example:

Decode function

Select OrderNum,

DECODE (Status,’O’, ‘Ordered’,’P’, ‘Packed,’ S’,’ Shipped’, ’A’,’Arrived’)

FROM Orders;

Case function

Select OrderNum

, Case(When Status=’O’ then ‘Ordered’

When Status =’P’ then Packed

When Status=’ S’ then ’Shipped’

else ’Arrived’) end

FROM Orders;

Both these commands will display Order Numbers with their respective Statuses like this,

Status O= Ordered

Status P= Packed

Status S= Shipped

Status A= Arrived
...