1. Registered User
Join Date
Sep 2003
Location
Posts
43

hi! ,

if x = 1 and y = 2 then
z = 3;
elsif x= 5 then
z := 6;
else
z := 7;
end if;

how do i encorporate this logic into
a single select decode statement ...

2. Registered User
Join Date
Mar 2002
Location
Posts
1,137
try using nested decodes or use case instead.

Alan

3. Registered User
Join Date
Dec 2003
Location
Noida, India.
Posts
171

## Re: re: decode logic

Using decode:
select x,y,decode(x,1,decode(y,2,3,7), 5,6,7) z from t;

Using case:
select x,y,case x when '1'
then case y when '2'
then 3
else 7
end
when '5' then 6
else 7
end z
from t;

Output from above two is:

X Y Z
- - ----------
1 2 3
1 3 7
5 6
6 7

Originally posted by hreddy007
hi! ,

if x = 1 and y = 2 then
z = 3;
elsif x= 5 then
z := 6;
else
z := 7;
end if;

how do i encorporate this logic into
a single select decode statement ...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•