Oracle decode函数

来源:互联网 发布:2007excel无法粘贴数据 编辑:程序博客网 时间:2024/06/01 07:21

1.低于2000的乘1.2,高于2000的乘1.15

           1.1  select t.quantity,decode(sign(quantity - 2000),1,quantity*1.15,-1,quantity*1.2) from table t;

结果如:

1000            1150

2000            2000--------------------------------------这里因为少了0的判断

3000            3600

            1.2   select score,decode(sign(score - 80),1,'良',0,'良',-1,'非良') from student t;


2.字段名为lock_date的字段做匹配,如果里面的值是null(空)则显示为 unlocked  否则就显示为locked.

            2.1  select username,decode(lock_date,null,'unlocked','locked') status from t;


oracle decode函数使用方法

多个嵌套

select id, decode(sign(score-85),1,'优秀',0,'优秀',-1, 
decode(sign(score-70),1,'良好',0,'良好',-1, 
decode(sign(score-60),1,'及格',0,'及格',-1,'不及格'))) 
from student;

0 0