格式:MONTHS_BETWEEN(DATE1,DATE2)

MONTHS_BETWEEN函数返回两个日期之间的月份数。
SQL> select months_between(to_date('', 'yyyymmdd'), to_date('', 'yyyymmdd')) as months from dual; MONTHS
---------- SQL> select months_between(to_date('', 'yyyymmdd'), to_date('', 'yyyymmdd')) as months from dual; MONTHS
---------- SQL> select months_between(to_date('', 'yyyymmdd'), to_date('', 'yyyymmdd')) as months from dual; MONTHS
---------- SQL> select months_between(to_date('', 'yyyymmdd'), to_date('', 'yyyymmdd')) as months from dual; MONTHS
---------- SQL> select months_between(to_date('', 'yyyymmdd'), to_date('', 'yyyymmdd')) as months from dual; MONTHS
---------- SQL> select months_between(to_date('', 'yyyymmdd'), to_date('', 'yyyymmdd')) as months from dual; MONTHS
----------
. SQL> select months_between(to_date('', 'yyyymmdd'), to_date('', 'yyyymmdd')) as months from dual; MONTHS
----------
1.06451613 SQL> select months_between(to_date('', 'yyyymmdd'), to_date('', 'yyyymmdd')) as months from dual; MONTHS
----------
. SQL> select months_between(to_date('', 'yyyymmdd'), to_date('', 'yyyymmdd')) as months from dual; MONTHS
---------- SQL> select months_between(to_date('', 'yyyymmdd'), to_date('', 'yyyymmdd')) as months from dual; MONTHS
----------
1.03225806 /=0.96774193548387096774193548387097
/=1.0645161290322580645161290322581
/=0.93548387096774193548387096774194
/=1.032258064516129032258064516129
在ORACLE中计算月份的差值,都是月底或是日期相同,都会按整月计算。
如果计算结果不是整数,ORACLE会把31作为分母来计算。
05-11 19:54