开发者

Decode function in Oracle

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 :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜