I need to write a script in pl/sql where I get the previous period. Period in the accounting system is defined as YYYYMM i.e for this month the current period would be 201304 and previous months period would be 201303.
For one of my functions a period is passed I need to get the previous period. So for example if the period that is passed is 201301 then the query needs to return 201212
SQL only:
SELECT TO_CHAR(ADD_MONTHS(TO_DATE(current_period, 'YYYYMM'), -1), 'YYYYMM')
FROM dual;
PL/SQL:
previous_period := TO_CHAR(ADD_MONTHS(TO_DATE(current_period, 'YYYYMM'), -1), 'YYYYMM');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With