CREATE OR REPLACE PROCEDURE SP_SF_CHECKZJLX -- MODIFICATION HISTORY -- Person Date Comments -- cailongquan 2022.06.02 create by MZSF-20220602-003; ( as_IdCardType in varchar, --卡类型 as_IdCard in varchar, --卡号 as_YHMSG0 out varchar, --存储过程提示的错误信息 as_SYSMSG out varchar, --系统提示的错误信息 as_code out number --返回值 ) as len number(5); -- 卡号长度 result number(20); -- 返回值 tmp varchar2(100); -- 临时变量 begin -- 默认为成功 as_code := 1; -- 获取卡号长度 if as_IdCard is null then len := 0; else len := length(as_IdCard); end if; -- 初始化提示开头 as_YHMSG0:='【'||as_IdCardType||'】'; /*SP_SF_CHECKSFZH(身份证号) 返回值说明: -1 位数不对 -2 出生日期超出范围 -3 含有非法字符 -4 校验码错误 -5 地区码非法 -9 为空值 1 通过校验 */ if as_IdCardType = '身份证' then select SP_SF_CHECKSFZH(as_IdCard) into result from dual; if result = -1 then as_code:=0; as_YHMSG0:=as_YHMSG0||'位数不对'; -- elsif result = -2 then -- as_code:=0; -- as_YHMSG0:='出生日期超出范围'; -- elsif result = -3 then -- as_code:=0; -- as_YHMSG0:='含有非法字符'; -- elsif result = -4 then -- as_code:=0; -- as_YHMSG0:='校验码错误'; -- elsif result = -5 then -- as_code:=0; -- as_YHMSG0:='地区码非法'; -- elsif result = -9 then -- as_code:=0; -- as_YHMSG0:='不能为空'; end if; return; elsif as_IdCardType = '香港特区护照/港澳居民来往内地通行证' or as_IdCardType = '澳门特区护照/港澳居民来往内地通行证' then tmp:=upper(substr(nvl(as_IdCard, '0'), 1, 1));-- 截取第一个字符 if len <> 9 AND len <> 11 AND len <> 12 then as_code:=0; as_YHMSG0:=as_YHMSG0||'仅支持输入9或者11位字符,并且以H或M开头'; elsif tmp <> 'H' and tmp <> 'M' then as_code:=0; as_YHMSG0:=as_YHMSG0||'仅支持输入9或者11位字符,并且以H或M开头'; end if; return; elsif as_IdCardType = '台湾居民来往大陆通行证' then tmp:=upper(substr(nvl(as_IdCard, '0'), 1, 3));-- 截取前三个字符 if tmp <> 'TWN' then begin select to_number(as_IdCard) into result from dual; exception when others then result:=0; end; if len > 9 then as_code:=0; as_YHMSG0:=as_YHMSG0||'仅支持输入8位纯数字或9位字符串'; elsif (len = 8 and result = 0) or len < 8 then as_code:=0; as_YHMSG0:=as_YHMSG0||'仅支持输入8位纯数字或9位字符串'; end if; end if; return; elsif as_IdCardType = '中国护照' then tmp:=upper(substr(nvl(as_IdCard, '0'), 1, 1));-- 截取第一个字符 /** * E+8位数字 * E+26字母任意一位+7位数字 * G+8位数字 * P+7位数字 **/ if tmp not in ('P','E','G') then as_code:=0; as_YHMSG0:=as_YHMSG0||'仅支持以下规则: '||chr(13)||' E+8位数字'||chr(13)||' E+26字母任意一位+7位数字'||chr(13)||' G+8位数字'||chr(13)||' P+7位数字'; -- P开头校验 elsif tmp = 'P' and len <> 8 then as_code:=0; as_YHMSG0:=as_YHMSG0||'以“P”开头的证件号格式为:'||chr(13)||' P+7位数字'; elsif tmp = 'P' and len = 8 then begin select to_number(substr(as_IdCard, 2)) into result from dual; exception when others then result:=0; end; if result = 0 then as_code:=0; as_YHMSG0:=as_YHMSG0||'以“P”开头的证件号格式为:'||chr(13)||' P+7位数字'; end if; -- E开头校验 elsif tmp = 'E' and len <> 9 then as_code:=0; as_YHMSG0:=as_YHMSG0||'以“E”开头的证件号格式为:'||chr(13)||' E+8位数字 '||chr(13)||' E+26字母任意一位+7位数字'; elsif tmp = 'E' and len = 9 then tmp:=nvl(upper(substr(as_IdCard, 2, 1)), '0');-- 截取第二个字符 result:=ascii(tmp); -- 第二字符仅能是 A-Z和0-9 if not ((result >= ascii('A') and result < ascii('Z') ) or (result >= ascii('0') and result < ascii('9') ) ) then as_code:=0; as_YHMSG0:=as_YHMSG0||'以“E”开头的证件号格式为: '||chr(13)||' E+8位数字 '||chr(13)||' E+26字母任意一位+7位数字'; end if; -- 后7为只能是数字 tmp:=nvl(upper(substr(as_IdCard, 3)), '0');-- 截取第二个字符 begin select to_number(tmp) into result from dual; exception when others then result:=0; end; if result = 0 then as_code:=0; as_YHMSG0:=as_YHMSG0||'以“E”开头的证件号格式为:'||chr(13)||' E+8位数字 '||chr(13)||' E+26字母任意一位+7位数字'; end if; -- G开头校验 elsif tmp = 'G' and len <> 9 then as_code:=0; as_YHMSG0:=as_YHMSG0||'以“G”开头的证件号格式为:'||chr(13)||' G+8位数字'; end if; return; end if; exception when others then as_YHMSG0:='出错原因不详,请记录此信息并和系统管理员联系!'; as_SYSMSG:=substr(sqlerrm||'执行存储过程错误:SP_SF_CHECKZJH',1,200); as_code:= 0; rollback; end;