CREATE OR REPLACE
FUNCTION id_age (idcard_no IN VARCHAR2)
RETURN NUMBER
AS
age NUMBER;
BEGIN
IF (LENGTH(idcard_no)!=18) THEN
RETURN NULL;
ELSE
age:=floor(MONTHS_BETWEEN(sysdate, to_date(substr(idcard_no,7,8),'yyyyMMdd') ) / 12);
IF age>0 and age<200 THEN
RETURN age;
ELSE
RETURN null;
END IF;
END IF;
return age;
EXCEPTION
WHEN OTHERS THEN return null;
END;
oracle 身份证号获取年龄
于 2024-01-26 10:21:35 首次发布