10.04.2005

Werktage in gegebenen Zeitraum

Prinzipiell ist dies mit einer Abfrage zu erledigen:
select count(*)
from (
select rownum rnum
from all_objects
where rownum <= mEnd - mStart + 1 )
where to_char(mStart + rnum - 1, 'D' ) not in ( '6', '7' ) ;

Dies funktioniert immer dann, wenn Ende und Start "richtig" herum liegen.
Daher ist das Verpacken in eine kleine Funktione ratsam.

Diese lautet für Oracle:


CREATE OR REPLACE FUNCTION FU_Number_Work_Days(
StartDate date,
EndDate date)
RETURN NUMBER IS
Ret number;
Signum number;
mStart date;
mEnd date;
BEGIN
IF EndDate < StartDate
THEN
mEnd := StartDate;
mStart := EndDate;
Signum := -1;
ELSE
mStart := StartDate;
mEnd := EndDate;
Signum := 1;
END IF;

select count(*) into ret
from (
select rownum rnum
from all_objects
where rownum <= mEnd - mStart + 1 )
where to_char(mStart + rnum - 1, 'D' ) not in ( '6', '7' ) ;

return Ret * Signum;
END FU_Number_Work_Days;
/

Keine Kommentare: