常用数字转换类:ROUND:四舍五入 TRUNC:截取 MOD:取余 FLOOR 取整 POWER(n1,n2) 求N次方根 SIGN(n)
ROUND:四舍五入
round(number,a),以小数点位核心,a如果为0可以不写,表示取整;a为-1表示小数点前一位,即个位数;a为2则表示小数点后2位。
BYS@bys1>select round(555.555),round(555.555,-1),round(555.555,1),round(555.574,2) from dual;
ROUND(555.555) ROUND(555.555,-1) ROUND(555.555,1) ROUND(555.574,2)
-------------- ----------------- ---------------- ----------------
556 560 555.6 555.57
TRUNC按照指定的精度进行截取:
trunc(number,a),以小数点位核心,a如果为0可以不写,表示取整;a为-1表示小数点前一位,即个位数;a为2则表示小数点后2位。
BYS@bys1>select trunc(555.555),trunc(555.555,-1),trunc(555.555,1),trunc(555.574,2) from dual;
TRUNC(555.555) TRUNC(555.555,-1) TRUNC(555.555,1) TRUNC(555.574,2)
-------------- ----------------- ---------------- ----------------
555 550 555.5 555.57
MOD(n1,n2);取余数,返回一个n1除以n2的余数
BYS@bys1>select mod(10,3),mod(3,3),mod(2,3) from dual;
MOD(10,3) MOD(3,3) MOD(2,3)
---------- ---------- ----------
1 0 2
FLOOR 对给定的数字取整数
BYS@bys1>select floor(2345.67) from dual;
FLOOR(2345.67)
--------------
2345
POWER(n1,n2) 返回n1的n2次方根
BYS@bys1>select power(2,10),power(2,3) from dual;
POWER(2,10) POWER(2,3)
----------- ----------
1024 8
SIGN(n) 取数字n的符号,大于0返回1,小于0返回-1,等于0返回0
BYS@bys1>select sign(3),sign(-9),sign(0) from dual;
SIGN(3) SIGN(-9) SIGN(0)
---------- ---------- ----------
1 -1 0
###########################################################################################
###########################################################################################
其它不太常用数学计算函数:正切、余切、正弦、余弦、对数等
1.ABS 返回指定值的绝对值
SQL> select abs(100),abs(-100) from dual;
ABS(100) ABS(-100)
--------- ---------
100 100
2.ACOS 给出反余弦的值
SQL> select acos(-1) from dual;
ACOS(-1)
---------
3.1415927
4.ASIN 给出反正弦的值
SQL> select asin(0.5) from dual;
ASIN(0.5)
---------
.52359878
5.ATAN 返回一个数字的反正切值
SQL> select atan(1) from dual;
ATAN(1)
---------
.78539816
5.CEIL 返回大于或等于给出数字的最小整数
SQL> select ceil(3.1415927) from dual;
CEIL(3.1415927)
---------------
4
6.COS 返回一个给定数字的余弦
SQL> select cos(-3.1415927) from dual;
COS(-3.1415927)
---------------
-1
7.COSH 返回一个数字反余弦值
SQL> select cosh(20) from dual;
COSH(20)
---------
242582598
8.SIN 返回一个数字的正弦值
SQL> select sin(1.57079) from dual;
SIN(1.57079)
------------
1
9.SIGH 返回双曲正弦的值
SQL> select sin(20),sinh(20) from dual;
SIN(20) SINH(20)
--------- ---------
.91294525 242582598
10.SQRT 返回数字n的根
SQL> select sqrt(64),sqrt(10) from dual;
SQRT(64) SQRT(10)
--------- ---------
8 3.1622777
11.TAN 返回数字的正切值
SQL> select tan(20),tan(10) from dual;
TAN(20) TAN(10)
--------- ---------
2.2371609 .64836083
12.TANH 返回数字n的双曲正切值
SQL> select tanh(20),tan(20) from dual;
TANH(20) TAN(20)
--------- ---------
1 2.2371609
13. EXP 返回一个数字e的n次方根
SQL> select exp(2),exp(1) from dual;
EXP(2) EXP(1)
--------- ---------
7.3890561 2.7182818
14.LOG(n1,n2) 返回一个以n1为底n2的对数
SQL> select log(2,1),log(2,4) from dual;
LOG(2,1) LOG(2,4)
--------- ---------
0 2
15.LN 返回一个数字的对数值
SQL> select ln(1),ln(2),ln(2.7182818) from dual;
LN(1) LN(2) LN(2.7182818)
--------- --------- -------------
0 .69314718 .99999999