oracle身份证校验函数的实例代码-创新互联-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

oracle身份证校验函数的实例代码-创新互联

1、正则表达式写法:

成都创新互联从2013年创立,先为平阴等服务建站,平阴等地企业,进行企业商务咨询服务。为平阴企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
CREATE OR REPLACE FUNCTION Func_checkidcard (p_idcard IN VARCHAR2) RETURN INT
IS
  v_regstr   VARCHAR2 (2000);
  v_sum     NUMBER;
  v_mod     NUMBER;
  v_checkcode  CHAR (11)    := '10X98765432';
  v_checkbit  CHAR (1);
  v_areacode  VARCHAR2 (2000) := '11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,91,';
BEGIN
  CASE LENGTHB (p_idcard)
   WHEN 15
   THEN                              -- 15位
     IF INSTRB (v_areacode, SUBSTR (p_idcard, 1, 2) || ',') = 0 THEN
      RETURN 0;
     END IF;

     IF MOD (TO_NUMBER (SUBSTRB (p_idcard, 7, 2)) + 1900, 400) = 0
      OR 
      (
        MOD (TO_NUMBER (SUBSTRB (p_idcard, 7, 2)) + 1900, 100) <> 0
        AND 
        MOD (TO_NUMBER (SUBSTRB (p_idcard, 7, 2)) + 1900, 4) = 0
      )
     THEN                             -- 闰年
      v_regstr :=
        '^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$';
     ELSE
      v_regstr :=
        '^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$';
     END IF;

     IF REGEXP_LIKE (p_idcard, v_regstr) THEN
      RETURN 1;
     ELSE
      RETURN 0;
     END IF;
   WHEN 18
   THEN                               -- 18位
     IF INSTRB (v_areacode, SUBSTRB (p_idcard, 1, 2) || ',') = 0 THEN
      RETURN 0;
     END IF;
    
     IF MOD (TO_NUMBER (SUBSTRB (p_idcard, 7, 4)), 400) = 0
      OR 
      (
        MOD (TO_NUMBER (SUBSTRB (p_idcard, 7, 4)), 100) <> 0
        AND 
        MOD (TO_NUMBER (SUBSTRB (p_idcard, 7, 4)), 4) = 0
      )
     THEN                             -- 闰年
      v_regstr :=
        '^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$';
     ELSE
      v_regstr :=
        '^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$';
     END IF;

     IF REGEXP_LIKE (p_idcard, v_regstr) THEN
      v_sum :=
          ( TO_NUMBER (SUBSTRB (p_idcard, 1, 1))
          + TO_NUMBER (SUBSTRB (p_idcard, 11, 1))
          )
         * 7
        +  ( TO_NUMBER (SUBSTRB (p_idcard, 2, 1))
          + TO_NUMBER (SUBSTRB (p_idcard, 12, 1))
          )
         * 9
        +  ( TO_NUMBER (SUBSTRB (p_idcard, 3, 1))
          + TO_NUMBER (SUBSTRB (p_idcard, 13, 1))
          )
         * 10
        +  ( TO_NUMBER (SUBSTRB (p_idcard, 4, 1))
          + TO_NUMBER (SUBSTRB (p_idcard, 14, 1))
          )
         * 5
        +  ( TO_NUMBER (SUBSTRB (p_idcard, 5, 1))
          + TO_NUMBER (SUBSTRB (p_idcard, 15, 1))
          )
         * 8
        +  ( TO_NUMBER (SUBSTRB (p_idcard, 6, 1))
          + TO_NUMBER (SUBSTRB (p_idcard, 16, 1))
          )
         * 4
        +  ( TO_NUMBER (SUBSTRB (p_idcard, 7, 1))
          + TO_NUMBER (SUBSTRB (p_idcard, 17, 1))
          )
         * 2
        + TO_NUMBER (SUBSTRB (p_idcard, 8, 1)) * 1
        + TO_NUMBER (SUBSTRB (p_idcard, 9, 1)) * 6
        + TO_NUMBER (SUBSTRB (p_idcard, 10, 1)) * 3;
      v_mod := MOD (v_sum, 11);
      v_checkbit := SUBSTRB (v_checkcode, v_mod + 1, 1);

      IF v_checkbit = upper(substrb(p_idcard,18,1)) THEN
        RETURN 1;
      ELSE
        RETURN 0;
      END IF;
     ELSE
      RETURN 0;
     END IF;
   ELSE
     RETURN 0;  -- 身份证号码位数不对
  END CASE;
EXCEPTION
  WHEN OTHERS
  THEN
   RETURN 0;
END fn_checkidcard;
/
Show Err;

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章名称:oracle身份证校验函数的实例代码-创新互联
转载注明:http://kswsj.cn/article/hgpco.html

其他资讯