Oracle SQL - MONTHS_BETWEEN and ADD_MONTHS

Introduction

The following code shows how to use MONTHS_BETWEEN and ADD_MONTHS Function.

Demo

SQL>
SQL> select ename, months_between(sysdate,bdate)
  2  from   emp--   w  w w .j  a v  a2 s.co m
  3  where  deptno = 10;

ENAME    | MONTHS_BETWEEN(SYSDATE,BDATE)
-------- | -----------------------------
WARD     |                      00553.40
BLAKE    |                      00533.43
CLARK    |                      00514.17
KING     |                      00545.92
MARY     |                      00554.72

SQL>
SQL> select add_months('29-JAN-1996', 1) add_months_1
  2  ,      add_months('29-JAN-1997', 1) add_months_2
  3  ,      add_months('11-AUG-1997',-3) add_months_3
  4  from   dual;

ADD_MONTH | ADD_MONTH | ADD_MONTH
--------- | --------- | ---------
29-FEB-96 | 28-FEB-97 | 11-MAY-97

SQL>

Related Topic