|
原帖由 谁 于 2008-5-26 09:44 发表 ![]()
我的算法思路和hotiice差不多
不过字节比他的多多了
CREATE OR REPLACE function SYSTEM.my_add_months(p_date_string varchar2, p_months number) return varchar2 IS
t int:=p_date_string;
l int:=100;
y int:= t/l/l; m int:= mod(t/l,l); d int:= mod(t,l);
BEGIN
t := case when m=2 and d>=28 then case when not ((mod(y,4)=0 and mod(y,25)>0 or mod(y,16)=0) and d=28) then 1 end
when m in(4,6,9,11) and d=30 then 1 when d=31 then 1 end;
m := m+p_months;
y := trunc(y+(m-1)/12);
m := mod(mod(m,12)+11,12)+1;
l:=28;
if mod(y,4)=0 and (mod(y,25)>0 or mod(y,16)=0) then l:=29; end if;
d := case when m in(4,6,9,11) and (d>30 or t=1) then 30
when m=2 and (d>l or t=1) then l
when t=1 then 31
else d end;
RETURN y||lpad(m,2,'0')||d;
END;
/
SQL> /
Congratulation ... Code Length: 538 Bytes. Times: 00:00:04
这是按我的算法思路走,最少的字节数了吧 
当然我的最终成绩,还是按照555字节来定
这三个数,也好听
更少的是这个
CREATE OR REPLACE function my_add_months(p_date_string varchar2, p_months number) return varchar2 IS
t int:=p_date_string;
l int:=100;
y int:= t/l/l; m int:= mod(t/l,l); d int:= 31-mod(t,l);
BEGIN
t := case when m=2 and d<4 then case when not ((mod(y,4)=0 and mod(y,25)>0 or mod(y,16)=0) and d=3) then 1 end
when m in(4,6,9,11) and d=1 or d=0 then 1 end;
m := m+p_months;
y := y+(m-7)/12;
m := mod(mod(m,12)+11,12)+1;
l:=3;
if mod(y,4)=0 and (mod(y,25)>0 or mod(y,16)=0) then l:=2; end if;
d := case when m in(4,6,9,11) and (d<1 or t=1) then 1
when m=2 and (d<l or t=1) then l
when t=1 then 0
else d end;
RETURN y*10000+m*100+31-d;
END;
/
同时还拒绝了漏洞
SQL> /
Congratulation ... Code Length: 516 Bytes. Times: 00:00:03
调用完成。
已用时间: 00: 00: 03.25
SQL> /
Congratulation ... Code Length: 516 Bytes. Times: 00:00:03
调用完成。
已用时间: 00: 00: 03.21
SQL> /
Congratulation ... Code Length: 516 Bytes. Times: 00:00:03
调用完成。
已用时间: 00: 00: 03.21
SQL> /
Congratulation ... Code Length: 516 Bytes. Times: 00:00:03
调用完成。
已用时间: 00: 00: 03.21 |
|