首页 > 代码库 > Oracle基础 (十二)数学函数

Oracle基础 (十二)数学函数

数学函数:

ABS(n):求绝对值

SELECT ABS(-15),ABS(15) FROM DUAL;   --获取15的绝对值结果:15,15

 

BITAND(X,Y):返回X,Y进行位与(AND)的运算结果

SELECT BITAND(1,0), BITAND(0,1), BITAND(0,0), BITAND(1,1), BITAND(1100, 1010) FROM DUAL;     --返回对x,y进行位与(AND)操作的结果结果:0,0,0,1,64

 

CEIL(n):向上取整

SELECT CEIL(44.123),CEIL(-44.123) FROM dual;    --向上取整结果:45,-44

 

FLOOR(n):向下取整

SELECT FLOOR(44.567),FLOOR(-44.567) FROM dual;   --向下取整结果:44,-45

 

ROUND(m,n):四舍五入

SELECT ROUND(44.567),ROUND(44.123),ROUND(-44.123),ROUND(-44.567) FROM dual;   --四舍五入结果:45,44,-44,-45SELECT Round(44.567,2) FROM dual;   --四舍五入,保留两位小数结果:44.57

 

TRUNC(m,n):截取

SELECT TRUNC(44.567),TRUNC(44.123),TRUNC(-44.123),TRUNC(-44.567) FROM dual;   --截断结果:44,44,-44,-44SELECT TRUNC(44.567,2) FROM dual;   --截断结果:44.56

 

SIGN(n):取符号

SELECT SIGN(-19) FROM dual;       --取符号,正数为1,负数为-1,0为0结果:-1

 

SIN(n) :正弦

SELECT SIN(3) FROM DUAL;      --求3的正弦结果:0.141120008059867

 

COS(n):余弦

SELECT COS(3) FROM DUAL;      --求3的余弦结果:-0.989992496600445

 

POWER(m,n):m的n次冥

SELECT POWER(2,8) from dual;    --2的8次方结果:256

 

SQRT(n):开平方根

SELECT SQRT(9) FROM dual;       --开平方根结果:3

 

MOD(m,n):取余

SELECT MOD(10,3) FROM dual;     --10 mod 2 (取余)结果:1

 

Oracle基础 (十二)数学函数