oracle - PL/SQL --next date based on Frequency -
i looking oracle
function or procedure calculate next date based on input date
, frequency(yearly,half yearly, quarterly )
.
for example
input date frequency next occurrence date 1-jan-2016 quarterly 1-apr-2016 1-jan-2016 yearly 1-jan-2017
look @ oracle function add_months( date, number_months )
monthly, quarterly, yearly results.
for example, next quarter 3 months. if input date first quarter use:
add_months( 01-jan-2016, 3 )
to next quarter.
example sql:
select to_date('01-jan-2016', 'dd-mon-yyyy') "input date", 'quarterly' "frequency", add_months(to_date('01-jan-2016', 'dd-mon-yyyy'), 3) "next occurrence date" dual union select to_date('01-jan-2016', 'dd-mon-yyyy') "input date", 'yearly' "frequency", add_months(to_date('01-jan-2016', 'dd-mon-yyyy'), 12) "next occurrence date" dual ;
results:
input date frequency next occurrence date ------------------ --------- ------------------ 01-jan-16 quarterly 01-apr-16 01-jan-16 yearly 01-jan-17
Comments
Post a Comment