Hi All,
Please look at these tables (Customer and Rates), having some sample data. I've created a function for returning the interest percentage for a particular customer based upon his/her investment start date and end date. I'm getting the desired result but I'm wondering if I need calculate the composite interest here...then how can I do that? Suppose a customer has invested some amount for 45 days, then I need to calculate the interest for initial 30 days as 5% and additional 15 days as 6% and I need to give the final amount. In this case how can I pull this task off? Please give me some ideas and correct me if I'm wrong. I just want to know how can we do this interest calculation by an Oracle program?
Regards
BS2012
Customer Table
CUSTOMER_ID AMOUNT START_DATE END_DATE
1000 40000 15-JAN-13 15-FEB-13
1001 34000 15-DEC-12 15-FEB-13
1002 35678 15-NOV-12 15-FEB-13
Rates Table
RATE_PCT LOW_TENURE HIGH_TENURE
5 0 30
6 0 60
7 0 90
CREATE OR REPLACE FUNCTION
F_INTEREST_PCT (V_CUSTOMER_ID IN CUSTOMER.CUSTOMER_ID%TYPE)
RETURN NUMBER AS V_RATE_PCT NUMBER;
BEGIN
SELECT A.RATE_PCT INTO V_RATE_PCT
FROM RATES A, CUSTOMER B WHERE (B.END_DATE - B.START_DATE) BETWEEN A.LOW_TENURE AND A.HIGH_TENURE
AND B.CUSTOMER_ID = V_CUSTOMER_ID;
RETURN V_RATE_PCT;
EXCEPTION
WHEN NO_DATA_FOUND THEN
ROLLBACK;
DBMS_OUTPUT.PUT_LINE(SQLERRM);
WHEN OTHERS THEN
ROLLBACK;
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END F_INTEREST_PCT;