to calculate last business day for each month for corresponding to any given date for last five years

5 pts.
Tags:
Oracle
Oracle developers
Oracle development
Hi , i have created a function to calculate last business date for each month for 1 year . Now, I want to modify code to find out last business day for last 5 years. Please suggest me what changes i need to made in code . CREATE OR REPLACE FUNCTION LAST_MONTHLY_BUS_DATE_FOR_YEAR (P_DATE in date ) return NUMBER is cursor c1 is select LAST_BUS_DAY( ADD_MONTHS( trunc(P_DATE,'yyyy'), -1+ lev ) ) from ( select level LEV from dual connect by level < 13) ; v_last_bus_day date; BEGIN OPEN c1 ; loop fetch c1 into v_last_bus_day; exit when c1%notfound; insert into LAST_BUSINESS_DATE values (v_last_bus_day); end loop; return 1; End LAST_MONTHLY_BUS_DATE_FOR_YEAR;

Answer Wiki

Thanks. We'll let you know when a new response is added.

If I understood correctly, you could modify your cursor this way to get the last 5 years:

<pre>select LAST_BUS_DAY(add_months(trunc(sysdate,’yyyy’),-49+lev))
from (select level LEV from dual connect by level <= 60)</pre>

In general, for “n” years:

<pre>select LAST_BUS_DAY(add_months(trunc(sysdate,’yyyy’),-1-(12*(n-1))+lev))
from (select level LEV from dual connect by level <= (12*n))</pre>

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following