Oracle/Function
[Oracle - SQL Developer] Numerical Function : 숫자 함수
삐옥
2021. 11. 14. 00:01
Numerical Function 숫자 함수
숫자 함수(= 수학 함수)
- 자바의 Math 클래스와 비슷함
1. round()
2. floor()
3. trunc()
4. ceil()
5. mod()
ROUND()
- 반올림 함수
- number round(컬럼명) : 정수 반환
- number round(컬럼명, 소수이하지릿수) : 실수 반환
1
2
3
4
5
6
7
8
9
10
11
12
|
select round(height / weight), height / weight from tblHealthCare;
select
height / weight,
round(height / weight),
round(height / weight, 1),
round(height / weight, 2),
round(height / weight, 3),
round(height / weight, 0) --그냥 정수
from tblHealthCare;
select round(avg(pay)) || '원' as from tblHealthCare;
|
cs |
FLOOR(), TRUNC()
- 절삭 함수
- 무조건 내림 함수
- number floor(컬럼명)
- number trunc(컬럼명 [, 소수이하자릿수])
*[] : 써도되고 안 써도 된다.
1
2
3
4
5
6
7
8
9
|
select
height / weight,
floor(height / weight),
trunc(height / weight),
trunc(height / weight, 1),
trunc(height / weight, 2)
from tblHealthCare;
|
cs |
CEIL()
- 무조건 올림 함수
- number ceil(컬럼명)
1
2
3
4
5
6
7
|
select
height / weight,
round(height / weight),
floor(height / weight),
ceil(height / weight)
from tblHealthCare;
|
cs |
MOD()
- 나머지 함수
- number mod(피제수, 제수)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
select
mod(height, weight)
from tblHealthCare;
select
mod(10, 2), second
from tblHealthCare;
select
mod(10, 2), name
from tblMember;
select
mod(10, 4), name, '삐옥', 123
from tblCompany;
select
mod(10, 3)
from dual;
select * from dual; -- 임시 테이블임
-- 100분 = 1시간 40분
-- 100/60 : 몫(시간)
-- 100%60 : 나머지(분)
select
floor(100 / 60) as 시,
mod(100, 60) as 분
from dual;
select
abs(10), abs(-10),
power(2,2), power(2,3), power(2,4), -- 제곱
sqrt(4), sqrt(16), sqrt(64) -- 루트
from dual;
|
cs |