Advertisement
Advertisement
| 07.03.2008 at 04:33AM PDT, ID: 23536447 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: |
create or replace package body calendar_functions is
function is_working_day
(in_check_date in corp_calendar.c_holidaydate%TYPE)
return boolean
is
v_day_of_week varchar2(10);
temp_count number;
begin
v_day_of_week := upper(trim(to_char(in_check_date,'DAY')));
if v_day_of_week in ('SATURDAY','SUNDAY') then
return false;
else
select nvl(count(1),0) into temp_count from corp_calendar where c_holidaydate = in_check_date;
if temp_count > 0 then
return false;
end if;
end if;
return true;
end is_working_day;
function get_working_days
(in_startdate in corp_calendar.c_holidaydate%TYPE,
in_enddate in corp_calendar.c_holidaydate%TYPE,
in_compare_times in varchar2)
return number
is
v_current_checkdate corp_calendar.c_holidaydate%TYPE;
v_current_checkdatetime corp_calendar.c_holidaydate%TYPE;
v_current_total number(4,0) := 0;
v_short_startdate corp_calendar.c_holidaydate%TYPE := trunc(in_startdate,'DDD');
v_short_enddate corp_calendar.c_holidaydate%TYPE := trunc(in_enddate,'DDD');
v_times varchar2(1) := upper(in_compare_times);
e_times exception;
e_invalid_dates exception;
begin
if v_times <> 'Y' and v_times <> 'N' then
raise_application_error (-20111,'Invalid argument - must be Y or N');
end if;
if in_startdate > in_enddate then
raise_application_error (-20112,'End date must be later than start date.');
else
if v_short_startdate = v_short_enddate then
return 0;
end if;
end if;
v_current_checkdate := v_short_startdate + 1;
v_current_checkdatetime := in_startdate + 1;
while v_current_checkdate < v_short_enddate loop
if is_working_day(v_current_checkdate) then
v_current_total := v_current_total + 1;
end if;
v_current_checkdate := v_current_checkdate + 1;
if v_times = 'Y' then
v_current_checkdatetime := v_current_checkdatetime + 1;
end if;
end loop;
if v_times = 'N' then
v_current_total := v_current_total + 1;
else
if in_enddate > v_current_checkdatetime then
v_current_total := v_current_total + 1;
end if;
end if;
return v_current_total;
exception
when others then
if sqlcode = -20111 or sqlcode = -20112 then
dbms_output.put_line(sqlerrm);
end if;
end get_working_days;
function get_end_date
(in_startdate in corp_calendar.c_holidaydate%TYPE,
in_working_days in number,
in_compare_times in varchar2)
return date
is
v_current_checkdatetime corp_calendar.c_holidaydate%TYPE := in_startdate;
v_current_checkdate corp_calendar.c_holidaydate%TYPE := trunc(in_startdate,'DDD');
v_current_total number(4,0) := 0;
v_times varchar2(1) := upper(in_compare_times);
e_times exception;
e_invalid_working_days exception;
begin
if v_times <> 'Y' and v_times <> 'N' then
raise_application_error (-20111,'Invalid argument - must be Y or N');
end if;
if in_working_days < 1 then
raise_application_error (-20113,'Working days must be a positive number.');
end if;
while v_current_total < in_working_days loop
v_current_checkdate := v_current_checkdate + 1;
if v_times = 'Y' then
v_current_checkdatetime := v_current_checkdatetime + 1;
end if;
if is_working_day(v_current_checkdate) then
v_current_total := v_current_total + 1;
end if;
end loop;
if v_times = 'Y' then
return trunc(v_current_checkdatetime,'MI');
else
return v_current_checkdate;
end if;
exception
when others then
if sqlcode = -20111 or sqlcode = -20113 then
dbms_output.put_line(sqlerrm);
end if;
end get_end_date;
function get_start_date
(in_working_days in number,
in_enddate in corp_calendar.c_holidaydate%TYPE,
in_compare_times in varchar2)
return date
is
v_current_checkdatetime corp_calendar.c_holidaydate%TYPE := in_enddate;
v_current_checkdate corp_calendar.c_holidaydate%TYPE := trunc(in_enddate,'DDD');
v_current_total number(4,0) := 0;
v_times varchar2(1) := upper(in_compare_times);
e_times exception;
e_invalid_working_days exception;
begin
if v_times <> 'Y' and v_times <> 'N' then
raise_application_error (-20111,'Invalid argument - must be Y or N');
end if;
if in_working_days < 1 then
raise_application_error (-20113,'Working days must be a positive number.');
end if;
while v_current_total < in_working_days loop
v_current_checkdate := v_current_checkdate - 1;
if v_times = 'Y' then
v_current_checkdatetime := v_current_checkdatetime - 1;
end if;
if is_working_day(v_current_checkdate) then
v_current_total := v_current_total + 1;
end if;
end loop;
if v_times = 'Y' then
return trunc(v_current_checkdatetime,'MI');
else
return v_current_checkdate;
end if;
exception
when others then
if sqlcode = -20111 or sqlcode = -20113 then
dbms_output.put_line(sqlerrm);
end if;
end get_start_date;
end calendar_functions;
/
<%
' Database connection from an include file
%>
<!--#include file="DBConn.inc"-->
<%
'Set rs1 = DBConn.execute("select calendar_functions.get_start_date(4,to_date('03/07/2008','DD/MM/YYYY'),'N') from dual")
'Response.Write(rs1(0))
Set oCmd = Server.CreateObject("ADODB.Command")
oCmd.ActiveConnection = DBconn
oCmd.CommandText = "calendar_functions.get_start_date"
oCmd.CommandType = 4
Set pReturn = oCmd.CreateParameter ("RETURN_VALUE",adDBTimeStamp,adParamReturnValue)
oCmd.Parameters.Append pReturn
Set pWorkingDays = oCmd.CreateParameter ("in_working_days",adNumeric,adParamInput,,4)
oCmd.Parameters.Append pWorkingDays
Set pStartDate = oCmd.CreateParameter ("in_enddate",adDBTimeStamp,adParamInput,,CDate(Date))
oCmd.Parameters.Append pStartDate
Set pTimes = oCmd.CreateParameter ("in_compare_times",adVarChar,adParamInput,,"N")
oCmd.Parameters.Append pTimes
oCmd.Execute
'Set rs1 = Nothing
Set DBconn = Nothing
%>
|