|
create or replace function my_add_months(p_date_string varchar2,
p_months number)
return varchar2
as
x char(8):=p_date_string;
y int:=0;
m int;
n int:=substr(x,5,2);
p int:=x/10000;
d int:=mod(x,100);
l int:=0;
type t is table of int;
a t:=t(31,28,31,30,31,30,31,31,30,31,30,31);
begin
if n<>2 and a(n)=d then
l:=1;
elsif mod(p,4)=0 and mod (p,25)>0 or mod(p,16)=0 then
y:=1;
end if;
if n||d-y=228 then
l:=1;
end if;
n:=n+p_months;
m:=mod(p*12+n-1,12)+1;
y:=p+(n-m)/12;
if mod(y,4)=0 and mod (y,25)>0 or mod(y,16)=0 then
a(2):=29;
end if;
if d>a(m) or l=1 then
d:=a(m);
end if;
return y*10000+m*100+d;
end; |
|