function f_chk_sfz_jym(as_sfzh varchar2) return number
--校验身位最后一位是否合法
is
ai_list number:=1;
ai_i number:=17;
ai_code number:=0;
ai_mul number;
as_idcode varchar2(18);
as_18 char(1);
begin
as_idcode:=substrb(as_sfzh,1,17);
while ai_i > 0 loop
ai_list := mod(ai_list * 2,11);
ai_mul := to_number(substr(as_idcode,ai_i,1));
ai_code := ai_code + ai_mul * ai_list;
ai_i := ai_i - 1;
end loop;
ai_code := mod(ai_code,11);
ai_code :=mod((12 - ai_code),11);
if ai_code = 10 then
as_18 := 'X';
else
as_18 :=to_char(ai_code);
end if;
if as_18<>substrb(as_sfzh,18,1) then
return -1;
else
return 1;
end if;
end;[@more@]
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9879835/viewspace-997534/
,如需转载,请注明出处,否则将追究法律责任。