SELECT start_date, endday, endmonth,
CASE
WHEN start_date <
ADD_MONTHS (TRUNC (start_date, 'YYYY'),
endmonth - 1
)
+ endday
- 1
THEN ADD_MONTHS (TRUNC (start_date, 'YYYY'), endmonth - 1)
+ endday
- 1
ELSE ADD_MONTHS (TRUNC (start_date, 'YYYY'), endmonth + 11)
+ endday
- 1
END end_date
FROM ............