1. 날짜 ~ 시간 ('SECOND' , 'MINUTE', 'HOUR', 'DAY' )
SELECT TO_CHAR(SYSDATE + NUMTODSINTERVAL(2, 'HOUR'), 'YYYY-MM-DD HH24:MI:SS') FROM DUAL;
2. 년 ~ 월 ('YEAR', 'MONTH' )
SELECT TO_CHAR(SYSDATE + NUMTOYMINTERVAL(2, 'MONTH'), 'YYYY-MM-DD HH24:MI:SS')
TO_CHAR(ADD_MONTHS(SYSDATE, 2), 'YYYY-MM-DD HH24:MI:SS')
FROM DUAL;
SELECT TO_CHAR(SYSDATE + 1, 'YYYY-MM-DD HH24:MI:SS') FROM DUAL;
3. 시간차를 구하고 일시분초로 변환
SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') AS NOW
, TRUNC(SYSDATE - TO_DATE('20140623080000', 'YYYYMMDDHH24MISS')) AS DD
, TRUNC(MOD((SYSDATE - TO_DATE('20140623080000', 'YYYYMMDDHH24MISS')), 1) * 24) AS HH24
, TRUNC(MOD((SYSDATE - TO_DATE('20140623080000', 'YYYYMMDDHH24MISS')) * 24, 1) * 60) AS MI
, TRUNC(MOD((SYSDATE - TO_DATE('20140623080000', 'YYYYMMDDHH24MISS')) * 24 * 60, 1) * 60) AS SS
, MONTHS_BETWEEN(TO_DATE('201707', 'YYYYMM'), TO_DATE('201701', 'YYYYMM')) AS MM
FROM DUAL;
4. 시간계산
SELECT TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS "현재시간"
, TO_CHAR(SYSDATE - 1 / 24, 'YYYY/MM/DD HH24:MI:SS') AS "1시간 전"
, TO_CHAR(SYSDATE - 60 / (24 * 60), 'YYYY/MM/DD HH24:MI:SS') AS "60분 전"
, TO_CHAR(SYSDATE - 30 / (24 * 60 * 60), 'YYYY/MM/DD HH24:MI:SS') AS "30초 전"
, TO_CHAR(SYSDATE + 1 / 24, 'YYYY/MM/DD HH24:MI:SS') AS "1시간 후"
, TO_CHAR(SYSDATE + 60 / (24 * 60), 'YYYY/MM/DD HH24:MI:SS') AS "60분 후"
, TO_CHAR(SYSDATE + 30 / (24 * 60 * 60), 'YYYY/MM/DD HH24:MI:SS') AS "30초 후"
, TO_CHAR(SYSDATE + 1 / (24 * 60), 'YYYY/MM/DD HH24:MI:SS') AS "1분 후"
, TO_CHAR(SYSDATE + 1 / 24 / 60, 'YYYY/MM/DD HH24:MI:SS') AS "1분 후"
, TO_CHAR(TRUNC(SYSDATE) + 1 + 1 / 24, 'YYYY/MM/DD HH24:MI:SS') AS "내일 오전 1시"
, TO_CHAR(TRUNC(SYSDATE) + 23 / 24, 'YYYY/MM/DD HH24:MI:SS') AS "오늘 오후 11시"
FROM DUAL;