create type row_date as object(holiday DATE, datename varchar2(10));
create type table_date as table of row_date;
create or replace function get_holiday_date (p_date date DEFAULT sysdate)
RETURN table_date
PIPELINED
/**************************************
* Name: get_holiday_date
* Author: Lsx.
* Date: 2013-11-26.
* Function: 返回当前月星期日和星期六的表类型(不考虑跨月周末)。
* Parameters: p_date: 待分析的日期,默认系统当前时间。
* Example: select * from table(get_holiday_date());
返回 2013-11-2 星期六
2013-11-3 星期日
2013-11-9 星期六
2013-11-10 星期日
2013-11-16 星期六
2013-11-17 星期日
2013-11-23 星期六
2013-11-24 星期日。
**************************************/
as
v_type row_date;
v_type1 row_date;
l_date date;
g_first_date date;
g_last_date date;
l_time date;
l_r date;
l_l date;
begin
l_date := p_date;
g_first_date := trunc(l_date,'month');
g_last_date := trunc(last_day(l_date), 'dd');
select trunc(g_first_date, 'day') into l_time from dual;
if g_first_date > l_time then
g_first_date := l_time + interval '7' day;
end if;
while g_first_date <= g_last_date
loop
select trunc(g_first_date, 'day') into l_r from dual;
select trunc(g_first_date, 'day') -1 into l_l from dual;
v_type1 := row_date(l_r, '星期日');
v_type := row_date(l_l, '星期六');
pipe row(v_type);
pipe row(v_type1);
g_first_date := g_first_date + interval '7' day;
end loop;
end;
评论