PL/SQL ADD_MONTHS

The Oracle PL/SQL ADD_MONTHS function is used to add a specified number of months to a given date. The function returns a new date value that is the result of adding the specified number of months to the input date.

Syntax

The syntax for the ADD_MONTHS function is as follows:

ADD_MONTHS(date, n)

where date is the input date to which the months need to be added and n is the number of months to add. The value of n can be positive or negative.

Example

Here are a few examples of using the ADD_MONTHS function in Oracle PL/SQL:

Adding 3 months to a given date:

SELECT ADD_MONTHS(to_date('01-01-2022','dd-mm-yyyy'), 3) FROM dual;
Output: 01-04-2022

Adding -6 months to a given date:

SELECT ADD_MONTHS(to_date('01-01-2022','dd-mm-yyyy'), -6) FROM dual;
Output: 01-07-2021

Adding 12 months to a given date:

SELECT ADD_MONTHS(to_date('01-01-2022','dd-mm-yyyy'), 12) FROM dual;
Output: 01-01-2023

The ADD_MONTHS function is a powerful tool that can be used to calculate dates in Oracle PL/SQL. It is commonly used in financial and accounting applications to calculate due dates and payment schedules.