decode()
only supports equality. One of the reasons why we welcomed case()
when it was introduced back in the day was precisely because it allowed us to test greater than and less than.
However it is possible to nest decode()
calls and combine them with other functions to achieve the same outcome. This ...
select id
, var1
, decode(greatest(var1,20), 20, 1,
decode(least(var1,40), 40, 3, 2 )) as trans_var
from tab
/
... implements the logic of your case()
statement:
select id
, var1
, (case when Var1 < 20 then 1
when Var1 < 40 then 2
when Var1 >= 40 then 3
else NULL
end) as trans_var
from tab
/
SQL Fiddle demo.