MONTHS_BETWEEN 获取两个日期之间的月份数

原文链接:http://www.cnblogs.com/oradragon/archive/2012/08/31/2665822.html

Syntax

MONTHS_BETWEEN 获取两个日期之间的月份数

Purpose

MONTHS_BETWEEN returns number of months between dates date1 and date2. The month and the last day of the month are defined by the parameter NLS_CALENDAR. If date1 is later than date2, then the result is positive. If date1 is earlier than date2, then the result is negative. If date1 and date2 are either the same days of the month or both last days of months, then the result is always an integer. Otherwise Oracle Database calculates the fractional portion of the result based on a 31-day month and considers the difference in time components date1 and date2.

 

SQL> select months_between(add_months(sysdate, 5), sysdate) as "months" from dual
  2  /

    months
----------
         5

SQL> select months_between(sysdate, add_months(sysdate, 9)) as "months" from dual
  2  /

    months
----------
        -9

 

SQL> select months_between(sysdate+20, sysdate) as "months" from dual
  2  /

    months
----------
 .64516129

SQL> select months_between(sysdate, sysdate+31) as "months" from dual
  2  /

    months
----------
-1.0322581

SQL> select months_between(sysdate+30, sysdate) as "months" from dual
  2  /

    months
----------
         1

 

转载于:https://www.cnblogs.com/oradragon/archive/2012/08/31/2665822.html

上一篇:(数据库系统概论|王珊)第二章关系数据库-第四节:关系代数


下一篇:sql server 分页