decode [message #39036] |
Sun, 09 June 2002 20:09 |
jee
Messages: 2 Registered: June 2002
|
Junior Member |
|
|
how to decode a string.
i have something like this
select decode(empfunc, 'DC-USA', 'SOUTH', 'NY-USA', 'NORTH') from emp;
but its comming as empty string.
thanks in advance
jee.
|
|
|
Re: decode [message #39038 is a reply to message #39036] |
Sun, 09 June 2002 21:39 |
Vikas Gupta
Messages: 115 Registered: February 2002
|
Senior Member |
|
|
Hello,
The decode function works like this:
decode(empfunc, 'DC-USA', 'SOUTH', 'NY-USA', 'NORTH')
if empfunc = 'DC-USA' then
return 'SOUTH'
elseif empfunc = 'NY-USA' then
return 'NORTH'
else
return ''
end if;
Since you are getting an empty string that means the data does not match both the options and goes for the third.
Try this:
select decode(empfunc, 'DC-USA', 'SOUTH', 'NY-USA', 'NORTH','NOMATCH') from emp;
which translates to:
if empfunc = 'DC-USA' then
return 'SOUTH'
elseif empfunc = 'NY-USA' then
return 'NORTH'
else
return 'NOMATCH'
end if;
You will get the answer. Note this is case sensitive.
|
|
|
Re: decode [message #39048 is a reply to message #39036] |
Mon, 10 June 2002 06:12 |
jee
Messages: 2 Registered: June 2002
|
Junior Member |
|
|
thanks for responding
i have values in the table as DC-USA, do you know why it is returning empty string.
select decode(empfunc, 'DC-USA', 'SOUTH', 'NY-USA', 'NORTH','NOMATCH') from emp;
won't solve my problem entirely.
|
|
|