PL/SQL 获取一个月的天数排除周六周日

create or replace PROCEDURE GETWORKDAYS
(
sdate IN VARCHAR2
, TDAYS OUT INTEGER
) AS
totalDays INTEGER:=0;
tempDate VARCHAR2(20);
tempWeek INTEGER;
BEGIN
TDAYS:=0;
select add_months(to_date(sdate, 'yyyy-mm-dd'),1)-to_date(sdate, 'yyyy-mm-dd') into totalDays from dual;
tempDate:= to_char(to_date(sdate, 'yyyy-mm-dd'),'yyyy-mm-dd');
loop
exit when totalDays=0;
totalDays:=totalDays-1;
select to_char(to_date(tempDate, 'yyyy-mm-dd'),'d') into tempWeek from dual;
IF (tempWeek!=7 and tempWeek!=1)
then
TDAYS:=TDAYS+1;
END IF;
select to_char(to_date(tempDate, 'yyyy-mm-dd')+1,'yyyy-mm-dd') into tempDate from dual;

end loop;

END GETWORKDAYS;

posted @ 2016-10-18 17:31  沉于年华  阅读(1514)  评论(0编辑  收藏  举报