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
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
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
decode(someparam, value2, 1, 2)
The whole comparison to value1 seems redundant, as it is only going to the default value anyway.
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 :-)