-- 对月份进行判断,必须在1月到12月范围之内
if i_month not between 1 and 12 then
begin
return 0;
end;
end if;
-- 对日期的判断,1,3,5,7,8,10,12月最大日为31,4,6,9,11月最大日为30,2月若为闰年则为29,其它年则为28.
if i_day between 1 and 31 then
begin
if i_day=31 and i_month not in (1,3,5,7,8,10,12) then
begin
return 0;
end;
end if;
if i_month=2 then
begin
-- Rules 1:普通年能被4整除且不能被100整除的为闰年。
-- Rules 2:世纪年能被400整除的是闰年。
-- Rules 3:对于数值很大的年份,这年如果能整除3200,并且能整除172800则是闰年。如172800年是闰年,86400年不是闰年。
if ((mod(i_year,4)=0 and mod(i_year,100)<>0)
or mod(i_year,400)=0
or (mod(i_year,3200)=0 and mod(i_year,172800)=0)) then
begin
--若为闰年,则2月份最大日为29
if i_day>29 then
begin
return 0;
end;
end if;
end;
else
begin
--若不为闰年,则2月份最大日为28
if i_day>28 then
begin
return 0;
end;
end if;
end ;
end if;
end;
end if;
return 1;
end;
else
return 0;
end if;
end;