Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I use DECODE function for IF ELSE clauses 1

Status
Not open for further replies.

barnard90

IS-IT--Management
Mar 6, 2005
73
US
Hi

I have employee table .It has a field called employee marital status
which are like

Marital_status
-----------
101
102
103
104
105

Actually they mean

101 = Married
102 = Widowed
103 = Single
104 = Divorced
105 = Unknown

But these values are not stored in any table .
If I select Marital_status from Employee
select marital_status from employee
I get

101
102
103
104
105

But I want to get

Married
Widowed
Single
Divorced
Unknown

How do I get that with DECODE function . Please suggest code

thanks
 
DECODE(marital_status,
'101','Married',
'102','Widowed',
'103','Single',
'104','Divorced',
'105','Unknown', NULL)

Regards,



William Chadbourne
Oracle DBA
 
Barnard,

You can use:
Code:
SELECT ...
      ,DECODE(marital_status
              ,101,'Married'
              ,102,'Widowed'
              ,103,'Single'
              ,104,'Divorced'
              ,105,'Unknown'
              ,'Error')Marital
      ...
Let us know if this works well for you.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top