Added get_date_tab to generate table of dates

This commit is contained in:
Morten Braten 2015-09-24 19:08:17 +02:00
parent d2e71075ef
commit 5254680126
4 changed files with 64 additions and 0 deletions

View File

@ -3,3 +3,9 @@
select *
from table(date_util_pkg.explode_month(2011, 2))
-- generate a table of dates based on a "calendar string"
-- for calendar string syntax, see http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_sched.htm#i1009923
-- a start and stop date can be specified, it not specified it defaults to a year from now
select t.column_value
from table(date_util_pkg.get_date_tab('FREQ=WEEKLY; BYDAY=MON,WED,FRI', trunc(sysdate), trunc(sysdate+90))) t

View File

@ -1,4 +1,11 @@
Version 1.7.1
=============
- Added sms_util_pkg
- Minor enhancements to date_util_pkg
- Minor enhancements to string_util_pkg
Version 1.7.0
=============
- Split installation script into various modules (core, xml, amazon, microsoft, etc.)

View File

@ -628,5 +628,51 @@ begin
end explode_month;
function get_date_tab (p_calendar_string in varchar2,
p_from_date in date := null,
p_to_date in date := null) return t_date_array pipelined
as
l_from_date date := coalesce(p_from_date, sysdate);
l_to_date date := coalesce(p_to_date, add_months(l_from_date,12));
l_date_after date;
l_next_date date;
begin
/*
Purpose: get table of dates based on specified calendar string
Remarks: see https://oraclesponge.wordpress.com/2010/08/18/generating-lists-of-dates-in-oracle-the-dbms_scheduler-way/
see http://www.kibeha.dk/2014/12/date-row-generator-with-dbmsscheduler.html
Who Date Description
------ ---------- --------------------------------
MBR 24.09.2015 Created
*/
l_date_after := l_from_date - 1;
loop
dbms_scheduler.evaluate_calendar_string (
calendar_string => p_calendar_string,
start_date => l_from_date,
return_date_after => l_date_after,
next_run_date => l_next_date
);
exit when l_next_date > l_to_date;
pipe row (l_next_date);
l_date_after := l_next_date;
end loop;
return;
end get_date_tab;
end date_util_pkg;
/

View File

@ -103,5 +103,10 @@ as
function explode_month (p_year in number,
p_month in number) return t_period_date_tab pipelined;
-- get table of dates based on specified calendar string
function get_date_tab (p_calendar_string in varchar2,
p_from_date in date := null,
p_to_date in date := null) return t_date_array pipelined;
end date_util_pkg;
/