본문 바로가기
DB/Oracle

시간 형식 문자

by 태윤2 2020. 6. 23.
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
- HH24는 24시간으로 출력 HH12 | HH 는 12시간으로 출력
SELECT TO_CHAR(sysdate, 'HH24:MI:SS AM')
FROM dual;
 
TO_CHAR(SYSDATE,'HH24:MI:SSAM')
02:58:42 AM
 
SELECT TO_CHAR(sysdate, 'HH:MI:SS AM')
FROM dual;
 
TO_CHAR(SYSDATE,'HH:MI:SSAM')
02:59:20 AM
 
- AM/PM은 아무거나 적어도 출력하는 시간에 맞춰서 출력이 된다.
 
SELECT TO_CHAR(sysdate, 'HH:MI:SS PM')
FROM dual;
 
TO_CHAR(SYSDATE,'HH:MI:SSPM')
02:59:59 AM
 
- 시간 연산 확인 예제
 
SELECT TO_CHAR(sysdate+3/24'YY/MM/DD HH24:MI:SS')
FROM dual;
 
TO_CHAR(SYSDATE+3/24,'YY/MM/DDHH24:MI:SS')
20/06/23 06:00:54
 
SELECT TO_CHAR(sysdate-2/24'YY/MM/DD HH24:MI:SS')
FROM dual;
 
TO_CHAR(SYSDATE-2/24,'YY/MM/DDHH24:MI:SS')
20/06/23 01:01:25
 
SELECT TO_CHAR(hire_date, 'DD" of "MONTH'// of 문자열은 "" 로 감싸기
FROM employees;
 
TO_CHAR(HIRE_DATE,'DD"OF"MONTH')
------------------------------------------
17 of JUNE
21 of SEPTEMBER
13 of JANUARY
03 of JANUARY
 
-숫자를 출력하는 형식문자에 접미어를 사용할 수 있다.
sp : 숫자를 영문 스펠링으로 출력
th : 숫자를 서수 표기형식으로 출력
 
SELECT TO_CHAR(sysdate, 'dd'), TO_CHAR(sysdate, 'ddsp')
FROM dual;
 
TO_CHAR(SYSDATE,'DD')    TO_CHAR(SYSDATE,'DDSP')
                 23                  twenty-three
 
SELECT TO_CHAR(sysdate, 'dd'), TO_CHAR(sysdate, 'ddth')
FROM dual;
 
 
TO_CHAR(SYSDATE,'DD')    TO_CHAR(SYSDATE,'DDTH')
                    23                        23rd
 
SELECT TO_CHAR(sysdate, 'dd'), TO_CHAR(sysdate, 'ddthsp')
FROM dual;
 
 
TO_CHAR(SYSDATE,'DD')    TO_CHAR(SYSDATE,'DDTHSP')
                    23                twenty-third
 
 
- 접두어 fm(fill mode)는 자리값을 채우는 숫자0을 제거해서 출력해줌.
 
SELECT TO_CHAR(sysdate, 'DD/MM'), TO_CHAR(sysdate, 'DD/fmMM')
FROM dual;
 
TO_CHAR(SYSDATE,'DD/MM')    TO_CHAR(SYSDATE,'DD/FMMM')
                    23/06                        23/6
 
 
SELECT last_name, hire_date, TO_CHAR(NEXT_DAY(ADD_MONTHS(hire_date, 6),'MONDAY'),'DAY", the "Ddspth" of "Month", "YYYY'"Review"
FROM employees;
 
 
LAST_NAME    HIRE_DATE Review
--------------- --------- ------------------------------------------------------------
Grant        13-JAN-08 MONDAY   , the Fourteenth of July    , 2008
Whalen        17-SEP-03 MONDAY   , the Twenty-Second of March    , 2004
Hartstein    17-FEB-04 MONDAY   , the Twenty-Third of August   , 2004
Fay            17-AUG-05 MONDAY   , the Twentieth of February , 2006
Mavris        07-JUN-02 MONDAY   , the Ninth of December , 2002
Baer        07-JUN-02 MONDAY   , the Ninth of December , 2002
Higgins     07-JUN-02 MONDAY   , the Ninth of December , 2002
Gietz        07-JUN-02 MONDAY   , the Ninth of December , 2002
 
 
 
cs

 

 

'DB > Oracle' 카테고리의 다른 글

일반 함수  (0) 2020.06.23
TO_CHAR,NUMBER,DATE  (0) 2020.06.23
형식문자  (0) 2020.06.23
함수  (0) 2020.06.23
단일 행 함수(Single-row Function) - 수정  (0) 2020.06.05