Reputation: 1476
I have a condition like if(someparam!=value1) someparam=1 if(someparam!=value2) someparam =2 Default value = 1
How to use decode function for this condition
Upvotes: 3
Views: 1325
Reputation: 427
DECODE(SomeParam, someParam!=value1, 1, someParam!=value2, 2, 1)
The default is the same as when assessing someparam! = Value1 therefore can simplify it like this:
DECODE(SomeParam, someParam!=value2, 2, 1)
I hope this helps :-)
Upvotes: 0
Reputation: 262514
decode(someparam, value2, 1, 2)
The whole comparison to value1 seems redundant, as it is only going to the default value anyway.
Upvotes: 0
Reputation: 25370
DECODE(SomeParam, Value1, DECODE(SomeParam, Value2, 1, 2), 1)
but case is better:
case when someparam != Value1 then 1
whene someparam != Value2 then 2
else 1
end
Upvotes: 7