Oracle企业 2012-02-21
数值型函数
ROUND
TRUNC
MOD
CEIL
power
ROUND(列名|表达式,n)
四舍五入到小数点后的n位
idle> select round(458.734,0),round(458.734,1),round(458.734,-1) from dual;
ROUND(458.734,0) ROUND(458.734,1) ROUND(458.734,-1)
---------------- ---------------- -----------------
459 458.7 460
idle>
TRUNC(列名|表达式,n)
截取到小数点后的n位
idle> select trunc(458.734,0),trunc(458.734,1),trunc(458.734,-1) from dual
TRUNC(458.734,0) TRUNC(458.734,1) TRUNC(458.734,-1)
---------------- ---------------- -----------------
458 458.7 450
idle>
MOD(m,n)
求m除以n的余数
idle> select mod(10,3) from dual;
MOD(10,3)
----------
1
idle>
idle> select mod(3,10) from dual;
MOD(3,10)
----------
3
idle>
CEIL 取整 向上补1 和trunc相反
idle> select ceil(457.001) from dual; 后面只要有小数,就进一
CEIL(457.001)
-------------
458
idle>
power(底数,指数) 求次方
SQL> select power(10,3) from dual;
POWER(10,3)
-----------
1000
SQL>
Oracle中round() 函数与trunc()函数的比较,非常实用。x,y,数字型表达式,如果y不为整数则截取y整数部分,如果y>0则四舍五入为y位小数,如果y小于0则四舍五入到小数点向左第y位。