您的位置:首页 > 数据库 > Oracle

oracle 函数sign()、ABS()、decode()、case when、

2011-09-08 16:38 483 查看
sign()函数:取数字n的符号,大于0返回1,小于0返回-1,等于0返回0

e.g.select sign( 100 ),sign(-
100 ),sign( 0 ) from dual;

1.SIGN(123 ) SIGN(- 100 ) SIGN( 0 )
2.--------- ---------- ---------
3. 1 - 1 0

绝对值 ABS()
SQL> SELECT ABS(-7), ABS(7) FROM DUAL;
ABS(-7)     ABS(7)
---------- ----------
7          7


select a.*,decode(sign(a.房租-b.房租),1,'奢侈','普通')
from 表名 a,
(select 城市,avg(房租) 房租 from 表名 group by 城市) b
where a.城市=b.城市
select decode(sign(sal-2000),-1,'普通',0,'正常','奢侈'),sal from emp;

case when..
update personal
set salary= case when salary>=5000
then salary*0.9
when salary>=2000 and salary<4600
then salary*1.15
else salary end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: