i am trying to create a function that calculates and returns the total number calculate and return the total number of estimated hours involved in a given stage when it was first issued (ie before any changes to estimated hours were made). But i keep on coming up with errors. what am i doin wrong?



CREATE OR REPLACE FUNCTION estimated_hours (sno NUMBER)
RETURN NUMBER IS

count_records NUMBER;
BEGIN

FOR i IN (SELECT task_id
FROM task
WHERE stage_id = sno)
LOOP
SELECT COUNT (*)
INTO count_records
FROM task_history
WHERE task_ID = i.task_id;

IF estimated_hours IS NOT NULL
THEN
count_records:= estimated_hours;
ELSE
count_records:= estimated_hours + prev_est_date

END IF;
END LOOP;
RETURN return_var;
END;
/