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

来源:互联网 发布:telnet 端口链接失败 编辑:程序博客网 时间:2024/05/13 16:25

sign()函数:取数字n的符号,大于0返回1,小于0返回-1,等于0返回0

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

  1. 1.SIGN(123 ) SIGN(- 100 )   SIGN( 0 )     
  2. 2.--------- ---------- ---------     
  3. 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;
原创粉丝点击