Hi Mahesh,
it's not a bug, it's different logic, and according to this logic both are correct:
Teradata returns the last day of a month only when this day doesn't exist in the resulting month.
Oracle always returns the last day of a month when the starting date is the last day of a month.
Both return some unexpected results in special cases, e.g. adding one month and then substracting one month:
SELECT DATE '2013-01-31' AS d, ADD_MONTHS(d,1) AS d2, ADD_MONTHS(d2,-1);
d d2 ADD_MONTHS(d2, -1)
---------- ---------- ------------------
2013-01-31 2013-02-28 2013-01-28
SELECT DATE '2013-01-30' AS d, OADD_MONTHS(d,1) AS d2, OADD_MONTHS(d2,-1);
d d2 OADD_MONTHS(d2,-1)
---------- ---------- ------------------
2013-01-30 2013-02-28 2013-01-31When you search for it you'll find Oracle UDFs which mimic Teradata's verion of ADD_MONTHS, too :-)
Dieter
↧