The following might be considered "more elegant" (that in fact is a matter of taste), but probably not "quicker" as it actualy selects rows from the database. Anyway:
Of course the day-of-the-week numbers might be different for Sat-Sun on your system, this depends on your NLS_TERRITORY setting.Code:CREATE OR REPLACE FUNCTION working_days (p_start_date DATE, p_end_date DATE) RETURN NUMBER IS v_result NUMBER; BEGIN SELECT SUM(DECODE(DAY, '7', 0, '6', 0, 1)) INTO v_result FROM (SELECT TO_NUMBER(TO_CHAR(p_start_date + row_num,'D')) AS DAY FROM (SELECT ROWNUM-1 AS row_num FROM ALL_OBJECTS WHERE ROWNUM < TRUNC(p_end_date+1) - TRUNC(p_start_date-1))); RETURN v_result; END;




Reply With Quote