SQL-数字函数

数字函数

函数 结果 说明
ROUND(45.926, 2) 45.93 将值舍入到指定的小数位
TRUNC(45.926, 2) 45.92 将值截断到指定的小数位
MOD(1600, 300) 100 返回除法运算的余数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
SELECT ROUND(45.923,2), ROUND(45.923,0),
ROUND(45.923,-1)
FROM DUAL;
ROUND(45.923,2) ROUND(45.923,0) ROUND(45.923,-1)
--------------- --------------- ----------------
45.92 46 50
SELECT TRUNC(45.923,2), TRUNC(45.923),
TRUNC(45.923,-1)
FROM DUAL;
TRUNC(45.923,2) TRUNC(45.923) TRUNC(45.923,-1)
--------------- ------------- ----------------
45.92 45 40
SELECT last_name, salary, MOD(salary, 5000)
FROM employees
WHERE job_id = 'SA_REP';
LAST_NAME SALARY MOD(SALARY,5000)
------------------------- ---------- ----------------
Tucker 10000 0
Bernstein 9500 4500