CREATE OR REPLACE FUNCTION GET_YEARS_OF_AGE(P_BIRTHDAY IN DATE) RETURN NATURAL
IS
vYears NUMBER;
P_BASEDATE DATE := SYSDATE;
P_METHOD NUMBER := 0 ;
BEGIN
vYears := EXTRACT(YEAR FROM P_BASEDATE) - EXTRACT(YEAR FROM P_BIRTHDAY);
CASE P_METHOD
WHEN 2 THEN
vYears := vYears + 1;
WHEN 1 THEN
IF (TO_CHAR(P_BASEDATE+1, 'MMDD') < TO_CHAR(P_BIRTHDAY, 'MMDD')) THEN
vYears := vYears - 1;
END IF;
ELSE
IF (TO_CHAR(P_BASEDATE, 'MMDD') < TO_CHAR(P_BIRTHDAY, 'MMDD')) THEN
vYears := vYears - 1;
END IF;
END CASE;
RETURN vYears;
END;
/
Oracle中根据出生日期计算年龄
最新推荐文章于 2024-05-24 14:01:11 发布