Oracle中MONTHS_BETWEEN函数的使用

Oracle中MONTHS_BETWEEN函数的使用ORACLE中函数MONTHS_BETWEEN的使用 格式:MONTHS_BETWEEN(DATE1,DATE2)MONTHS_BETWEEN函数返回两个日期之间的月份数。SQL>selectmonths_between(to_date(‘20090228′,’yyyymmdd’),to_date(‘20080228′,’yyyymmdd’))asmonths…

大家好,又见面了,我是你们的朋友全栈君。

ORACLE中函数MONTHS_BETWEEN的使用

 

格式:MONTHS_BETWEEN(DATE1,DATE2)

MONTHS_BETWEEN函数返回两个日期之间的月份数。
SQL> select months_between(to_date('20090228', 'yyyymmdd'), to_date('20080228', 'yyyymmdd')) as months from dual;

    MONTHS
----------
        12

SQL> select months_between(to_date('20090228', 'yyyymmdd'), to_date('20080229', 'yyyymmdd')) as months from dual;

    MONTHS
----------
        12

SQL> select months_between(to_date('20080229', 'yyyymmdd'), to_date('20070228', 'yyyymmdd')) as months from dual;

    MONTHS
----------
        12

SQL> select months_between(to_date('20100331', 'yyyymmdd'), to_date('20100228', 'yyyymmdd')) as months from dual;

    MONTHS
----------
         1

SQL> select months_between(to_date('20100228', 'yyyymmdd'), to_date('20100128', 'yyyymmdd')) as months from dual;

    MONTHS
----------
         1

SQL> select months_between(to_date('20100327', 'yyyymmdd'), to_date('20100228', 'yyyymmdd')) as months from dual;

    MONTHS
----------
.967741935

SQL> select months_between(to_date('20100330', 'yyyymmdd'), to_date('20100228', 'yyyymmdd')) as months from dual;

    MONTHS
----------
1.06451613

SQL> select months_between(to_date('20100228', 'yyyymmdd'), to_date('20100130', 'yyyymmdd')) as months from dual;

    MONTHS
----------
.935483871

SQL> select months_between(to_date('20100228', 'yyyymmdd'), to_date('20100131', 'yyyymmdd')) as months from dual;

    MONTHS
----------
         1

SQL> select months_between(to_date('20100228', 'yyyymmdd'), to_date('20100127', 'yyyymmdd')) as months from dual;

    MONTHS
----------
1.03225806

30/31=0.96774193548387096774193548387097
33/31=1.0645161290322580645161290322581
29/31=0.93548387096774193548387096774194
32/31=1.032258064516129032258064516129
在ORACLE中计算月份的差值,都是月底或是日期相同,都会按整月计算。
如果计算结果不是整数,ORACLE会把31作为分母来计算。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/158207.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号