Oracle
 sql >> Database >  >> RDS >> Oracle

problema con Add_month in Oracle, ho bisogno di generare il ciclo di fatturazione

Un po' di calcolo potrebbe aiutare.

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>