身份证号码验证函数: CREATE OR REPLACE FUNCTION fn_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, 6, 2)) + 1900, 400) = 0 OR ( MOD (TO_NUMBER (SUBSTRB (p_idcard, 6, 2)) + 1900, 100) <> 0 AND MOD (TO_NUMBER (SUBSTRB (p_idcard, 6, 2)) + 1900, 4) = 0 ) THEN -- 闰年
v_regstr := '^[1-9][0-9]{5}[0-9]{2}((01030507081012)(0[1-9][1-2][0-9]3[0-1])(04060911)(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}((01030507081012)(0[1-9][1-2][0-9]3[0-1])(04060911)(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, 6, 4)), 400) = 0 OR ( MOD (TO_NUMBER (SUBSTRB (p_idcard, 6, 4)), 100) <> 0 AND MOD (TO_NUMBER (SUBSTRB (p_idcard, 6, 4)), 4) = 0 ) THEN -- 闰年
v_regstr := '^[1-9][0-9]{5}19[0-9]{2}((01030507081012)(0[1-9][1-2][0-9]3[0-1])(04060911)(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[0-9]{2}((01030507081012)(0[1-9][1-2][0-9]3[0-1])(04060911)(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)) )