---------通过身份证判断性别
create or replace function sex(id in varchar)return varchar
as
SFZHM varchar(50);
begin
if length(id)=18 then
select decode(mod(to_number(substr(id,17, 1)),2),0, '女',1,'男') into SFZHM from dual;
elsif length(id)=15 then
select decode(mod(to_number(substr(id,15, 1)),2),0, '女',1,'男') into SFZHM from dual;
else
select '未知' into SFZHM from dual;
end if;
return SFZHM;
end;
----------通过身份证判断年龄
create or replace function age(id in varchar)return varchar
as
SFZHM varchar(50);
begin
if length(id)=18 and to_number(substr(id,11,2))<13
and to_number(substr(id,13,2))<31 then
select floor(months_between(SYSDATE,to_date(substr(id,7,8),'yyyymmdd'))/12) into SFZHM from dual;
else
select 0 into SFZHM from dual;
end if;
return SFZHM;
end;