Data/Oracle
Oracle 생성날짜를 통해서 나이(age)를 표시하기
바리새인
2025. 1. 18. 08:45
WITH date_diff AS (
SELECT
TO_DATE('20250101 132344', 'YYYYMMDD HH24MISS') AS created_date,
SYSDATE AS current_date
FROM dual
)
SELECT
CASE
WHEN current_date - created_date >= 1 THEN
TRUNC(current_date - created_date) || ' days'
WHEN (current_date - created_date) * 24 >= 1 THEN
TRUNC((current_date - created_date) * 24) || ' hours'
ELSE
TRUNC(MOD((current_date - created_date) * 24 * 60, 60)) || ' minutes'
END AS age
FROM date_diff;