Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

Oracle add_months Tips


Oracle Database Tips by Donald Burleson

The add_months Oracle date function gives you the same day, n number of months away.  Note that the n can be positive or negative, so you can go backwards in time with add_months.  Using nls_date_format, add_months is one of the most powerful Oracle commands for computing future months and years.

select
  sysdate,
  add_months(sysdate,1),
  add_months(sysdate,2),
  add_months(sysdate,3),
  add_months(sysdate,4),
  add_months(sysdate,5),
  add_months(sysdate,6)
from
  dual;

SYSDATE   ADD_MONTH ADD_MONTH ADD_MONTH ADD_MONTH ADD_MONTH ADD_MONTH
--------- --------- --------- --------- --------- --------- ---------
24-JAN-05 24-FEB-05 24-MAR-05 24-APR-05 24-MAY-05 24-JUN-05 24-JUL-05

select
  sysdate,
  add_months(sysdate,-1),
  add_months(sysdate,-2),
  add_months(sysdate,-3),
  add_months(sysdate,-4),
  add_months(sysdate,-5),
  add_months(sysdate,-6)
from
  dual; 

SYSDATE   ADD_MONTH ADD_MONTH ADD_MONTH ADD_MONTH ADD_MONTH ADD_MONTH
--------- --------- --------- --------- --------- --------- ---------
24-JAN-05 24-DEC-04 24-NOV-04 24-OCT-04 24-SEP-04 24-AUG-04 24-JUL-04

The Oracle add_months SQL function is a great way to perform date manipulation.  Here are some syntax examples of add_months:

NEXT_DAY(ADD_MONTHS(trunc(sysdate,'Q'),3),'SUNDAY')

add_months( sysdate-1 )

This add_months will return the first Monday of each quarter year:

'next_day(add_months(trunc(sysdate, "q"), 3), "monday")'
'next_day(add_months(trunc(systimestamp, "q"), 3), "monday")'

Here, add_months is used to give the last day of last month:

select
   last_day(add_months(sysdate,-1))
from dual;

The Oracle documentation gives us the following example for returning "the month after the hire_date in the sample table employees" using add_months:

SELECT TO_CHAR(
     ADD_MONTHS(hire_date,1),
     'DD-MON-YYYY') "Next month"
     FROM employees
     WHERE last_name = 'Baer';

Next Month
-----------
07-JUL-1994

 

If you like Oracle tuning, you may enjoy my new book "Oracle Tuning: The Definitive Reference", over 900 pages of BC's favorite tuning tips & scripts. 

You can buy it direct from the publisher for 30%-off and get instant access to the code depot of Oracle tuning scripts.


 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster
 
 
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.