Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

problema com Add_month no oracle, preciso gerar ciclo de cobrança


Um pouco de cálculo pode ajudar.
SQL> with test (col) as
  2    (select date '2020-03-27' from dual union all
  3     select date '2020-01-10' from dual union all
  4     select date '2018-02-27' from dual union all
  5     select date '2018-02-28' from dual
  6    )
  7  select col,
  8    least(add_months(col, 1),
  9          add_months(trunc(col, 'mm'), 1) + (col - trunc(col, 'mm'))
 10         ) result
 11  from test
 12  order by col;

COL        RESULT
---------- ----------
27.02.2018 27.03.2018
28.02.2018 28.03.2018
10.01.2020 10.02.2020
27.03.2020 27.04.2020

SQL>