表数据;
MENU_ID | IS_TREE |
---|---|
0001 | 1 |
0002 | 1 |
0101 | 2 |
0102 | |
0103 | |
0201 | 5 |
0202 | 6 |
--------------使用decode函数
select b.menu_id,decode(b.is_tree,'1','1vv','2','2vv',null,'isnullvalue','defaultvaluehehe') tree
from menutree b
--------------使用case when then else达到相同效果
select c.menu_id,
case
when c.is_tree is null then 'isnullvalue'
when c.is_tree='1' then '1vv'
when c.is_tree='2' then '2vv'
else 'defaultvaluehehe'
end tree
from menutree c
上面2个sql效果是一样的。
MENU_ID | TREE |
---|---|
0001 | 1vv |
0002 | 1vv |
0101 | 2vv |
0102 | isnullvalue |
0103 | isnullvalue |
0201 | defaultvaluehehe |
0202 | defaultvaluehehe |