MONTHS_BETWEEN 함수는 주어진 두 개의 DATE 값 간의 차이를 월 단위로 반환하며, 리턴 값은 DOUBLE 타입이다. 인자로 지정된 두 날짜가 동일하거나, 해당 월의 말일인 경우에는 정수 값을 반환하지만, 그 외의 경우에는 날짜 차이를 31로 나눈 값을 반환한다.
MONTHS_BETWEEN(date_argument, date_argument)
date_argument :
• date
• NULL
--it returns the negative months when the first argument is the previous date
SELECT MONTHS_BETWEEN(DATE '2008-12-31', DATE '2010-6-30');
======================================================
-1.800000000000000e+001
--it returns integer values when each date is the last dat of the month
SELECT MONTHS_BETWEEN(DATE '2010-6-30', DATE '2008-12-31');
======================================================
1.800000000000000e+001
--it returns months between two arguments when explicitly casted to DATE type
SELECT MONTHS_BETWEEN(CAST (SYS_TIMESTAMP AS DATE), DATE '2008-12-25');
====================================================================
1.332258064516129e+001
--it returns months between two arguments when explicitly casted to DATE type
SELECT MONTHS_BETWEEN(CAST (SYS_DATETIME AS DATE), DATE '2008-12-25');
===================================================================
1.332258064516129e+001