1. ν λ³ν ν¨μλ
- μ€λΌν΄μμ μ 곡νλ μλ£νμ νμμ λ°λΌ λ°κΏ μ£Όμ΄μΌ ν λ μ§μ λ μλ£νμ λ°κΏμ£Όλ ν¨μ
- μμμ ν λ³ν(implicit type conversion) : μλ ν λ³ν. μ«μλ‘ μΈμ κ°λ₯ν λ¬Έμ λ°μ΄ν°κ° μλμΌλ‘ μ«μλ‘ λ°λ ν μ°μ° μν
- λͺ μμ ν λ³ν (explicit type conversion) : ν λ³ν ν¨μλ₯Ό μ¬μ©νμ¬ μ§μ μλ£νμ λ³νν΄ μ£Όλ λ°©μ
2. λ μ§, μ«μ λ°μ΄ν°λ₯Ό λ¬Έμ λ°μ΄ν°λ‘ λ³ννλ TO_CHAR ν¨μ
- 'NLS_DATE_LANGUAGE = language' μ languageμλ KOREAN, ENGLISH, JAPANESE λ±μ΄ κ°λ₯
TO_CHAR([λ μ§ λ°μ΄ν°], [μΆλ ₯λκΈΈ μνλ λ¬Έμ νν])
TO_CHAR([λ μ§ λ°μ΄ν°], [μΆλ ₯λκΈΈ μνλ λ¬Έμ νν], 'NLS_DATE_LANGUAGE = [language]'(μ ν))
-- 0. νΉμ μΈμ΄μ λ§μΆ° μΆλ ₯
SELECT TO_CHAR(SYSDATE, 'MM') AS MM,
TO_CHAR(SYSDATE, 'MON', 'NLS_DATE_LANGUAGE = KOREAN') AS MON_KOR,
TO_CHAR(SYSDATE, 'MONTH', 'NLS_DATE_LANGUAGE = KOREAN') AS MONTH_KOR,
TO_CHAR(SYSDATE, 'MON', 'NLS_DATE_LANGUAGE = ENGLISH') AS MON_ENG,
TO_CHAR(SYSDATE, 'MONTH', 'NLS_DATE_LANGUAGE = ENGLISH') AS MONTH_ENG,
TO_CHAR(SYSDATE, 'MON', 'NLS_DATE_LANGUAGE = JAPANESE') AS MON_JPN,
TO_CHAR(SYSDATE, 'MONTH', 'NLS_DATE_LANGUAGE = JAPANESE') AS MONTH_JPN,
FROM DUAL;
-- 1. λ μ§ νν νμ
SELECT SYSDATE, TO_CHAR(SYSDATE, 'CC') AS CC,
TO_CHAR(SYSDATE, 'YYYY') AS YYYY, TO_CHAR(SYSDATE, 'YY') AS YY,
TO_CHAR(SYSDATE, 'MM') AS MM, TO_CHAR(SYSDATE, 'MON') AS MON,
TO_CHAR(SYSDATE, 'MONTH') AS MONTH, TO_CHAR(SYSDATE, 'DD') AS DD,
TO_CHAR(SYSDATE, 'DDD') AS DDD, TO_CHAR(SYSDATE, 'DY') AS DY,
TO_CHAR(SYSDATE, 'DAY') AS DAY, TO_CHAR(SYSDATE, 'W') AS W
FROM DUAL;
-- 2. μκ° νν νμ
SELECT SYSDATE,
TO_CHAR(SYSDATE, 'HH24:MI:SS') AS HH24MISS,
TO_CHAR(SYSDATE, 'HH12:MI:SS') AS HH12MISS,
TO_CHAR(SYSDATE, 'HH:MI:SS AM') AS HHMISS_AM,
TO_CHAR(SYSDATE, 'HH:MI:SS PM') AS HHMISS_PM,
TO_CHAR(SYSDATE, 'HH:MI:SS A.M.') AS HHMISS_AM2
FROM DUAL;
-- 3. μ«μ λ°μ΄ν° νν νμ
SELECT TO_CHAR(123456, '$9,999,999') AS NUM9_$,
TO_CHAR(123456, 'L9,999,999') AS NUM9_L,
TO_CHAR(123456, '9,999,999.99') AS NUM9_1,
TO_CHAR(123456, '$0,000,000') AS NUM0_$,
TO_CHAR(123456, 'L0,000,000') AS NUM0_L,
TO_CHAR(123456, '0,000,000.00') AS NUM0_1
FROM DUAL;
3. λ¬Έμ λ°μ΄ν°λ₯Ό μ«μ λ°μ΄ν°λ‘ λ³ννλ TO_NUMBER ν¨μ
- λ¬Έμμ΄μ μ§μ λ ννμ μ«μ λ°μ΄ν°λ‘ λ³ν
- μ«μ λ°μ΄ν°κ° κ°κ³΅λ λ¬Έμ λ°μ΄ν°λ‘ μ μ₯λμ΄ μκ³ κ·Έ λ°μ΄ν°λ₯Ό μ°μ μ°μ°μ μ¬μ©νκ³ μ ν κ²½μ° μ¬μ©
TO_NUMBER([λ¬Έμμ΄ λ°μ΄ν°], [μΈμλ μ«μ νν])
-- 1.
SELECT TO_NUMBER('1,500', '999,999') - TO_NUMBER('1,300', '999,999')
FROM DUAL;
(1) TO_NUMBER('1,500', '999,999') - TO_NUMBER('1,300', '999,999') : μ«μ 1500κ³Ό 1300 μ΄ κ°κ³΅λμ΄ κ³μ°μ΄ λΆκ°λ₯ν΄ μ«μ λ°μ΄ν°λ‘ λ³ννμ¬ κ³μ°νλ€. κ²°κ³Όκ° 200
4. λ¬Έμ λ°μ΄ν°λ₯Ό λ μ§ λ°μ΄ν°λ‘ λ³ννλ TO_DATE ν¨μ
- λ¬Έμμ΄μ μ§μ λ ννμ λ μ§ λ°μ΄ν°λ‘ λ³ν
TO_DATE([λ¬Έμμ΄ λ°μ΄ν°], [μΈμλ λ μ§ νν])
-- 1. 2.
SELECT TO_DATE('2021/03/02', 'YYYY-MM-DD') AS TODATE1,
TO_DATE('20210302', 'YYYY-MM-DD') AS TODATE2
FROM DUAL;
(1) (2) : 2021-03-21 λ‘ λ³νλ¨