Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example code of oracle ID card check function

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. Regular expression is written:

CREATE OR REPLACE FUNCTION Func_checkidcard (p_idcard IN VARCHAR2) RETURN INTIS v_regstr VARCHAR2 (2000); v_sum NUMBER; v_mod NUMBER; v_checkcode CHAR (11): = '10X98765432; v_checkbit CHAR (1); v_areacode VARCHAR2 (2000): =' 11, 13, 13, 14, 15, 21, 23, 31, 3, 3, 3, 35, 36, 37, 41, 41, 43, 4, 4, 45, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, BEGIN CASE LENGTHB (p_idcard) WHEN 15 THEN-15 bit 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) = 0 OR (MOD (TO_NUMBER (SUBSTRB (p_idcard, 7,2)) + 1900) 0 AND MOD (TO_NUMBER (SUBSTRB (p_idcard, 7,2)) + 1900 4) THEN-- Leap year 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) | 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] | 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 bit 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 (p_idcard (p_idcard, 7,4)) 4) THEN-- Leap year 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 (p_idcard (p_idcard, 2,1)) + TO_NUMBER (SUBSTRB (p_idcard, 12) ) * 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) ) * 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) ) * 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 (pairidcardmeme 1881)) THEN RETURN 1; ELSE RETURN 0ten end IF; ELSE RETURN 0There end IF; ELSE RETURN 0;-- the number of ID card numbers does not match END CASE;EXCEPTION WHEN OTHERS THEN RETURN 0ten end fn_checkidcard / Show Err

2. Irregular expression writing

Create Or Replace Function Func_checkIdcard (p_idcard in varchar2) Return NumberIs v_sum Number; v_mod Number; v_length Number; v_date Varchar2 (10); v_isDate Boolean; v_isNumber Boolean; v_isNumber_17 Boolean; v_checkbit CHAR (1); v_checkcode CHAR (11): = '10X98765432; v_areacode VARCHAR2 (2000): =' 11, 13, 13, 14, 15, 21, 23, 31, 3, 3, 3, 35, 36, 37, 41, 41, 4, 3, 3, 3, 35, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, -- [isNumber]-- Function isNumber (p_string in varchar2) Return Boolean Is i number; k number; flag boolean; v_length number; Begin / * algorithm: judge whether it is numeric or not by ASCII code, between [48,57]. Select ascii ('0'), ascii ('1'), ascii ('2'), ascii ('3'), ascii ('4'), ascii ('5'), ascii ('6'), ascii ('7'), ascii ('8'), ascii ('9') from dual; * / flag: = True; select length (p_string) into v_length from dual For i in 1..v_length loop k: = ascii (substr (paired string.iPhone1); if k

< 48 or k >

57 then flag: = False; Exit; end if; end loop; Return flag; End isNumber;-- [isDate]-- Function isDate (p_date in varchar2) Return Boolean Is v_flag boolean; v_year number; v_month number; v_day number; v_isLeapYear boolean; Begin-- [initialization]-- v_flag: = True -- [get information]-- v_year: = to_number (substr (pmemordatememe 1)); v_month: = to_number (substr (pmemordatemem5) 2); v_day: = to_number (substr)) -- [judge whether it is a leap year]-- if (mod) = 0) Or (mod) 0 And mod (venerable yearbook 4) = 0) then v_isLeapYear: = True; else v_isLeapYear: = False; end if;-- [judge month]-- if v_month

< 1 Or v_month >

12 then v_flag: = False; Return vengeance; end if;-- [date of judgment]-- if v_month in (1 v_day 3, 5 5 7, 8 10, 12) and

< 1 or v_day >

31) then v_flag: = False; end if; if v_month in (4, 6, 9, 11) and (v_day

< 1 or v_day >

30) then v_flag: = False; end if; if v_month in (2) then if (v_isLeapYear) then-[leap year]-if (v_day

< 1 or v_day >

29) then v_flag: = False; end if; else-- [non-leap years]-- if (v_day

< 1 or v_day >

28) then v_flag: = False; end if;-- [return result]-- Return vs. End isDate Begin / * return value description:-1 ID card number digit incorrect-2 ID card number birth date out of range-3 ID card number contains illegal characters-4 ID card number check code error-5 ID card number area code illegal ID card number passed check * /-[length check]-- if p_idcard is null then return-1; end if Select lengthb (p_idcard) into v_length from dual; if v_length not in (15 then return 18) then return-1; end if;-- [area Code check]-- if instrb (v_areacode, substr (p_idcard, 1,2) | |',') = 0 then return-5; end if;-- [format check]-- if v_length = 15 then v_isNumber: = isNumber (p_idcard) If not (v_isNumber) then return-3; end if; elsif v_length = 18 then v_isNumber: = isNumber (p_idcard); v_isNumber_17: = isNumber (substr (v_isNumber) or (v_isNumber_17 and upper (substr (pairidcard1)) ='X') then return-3; end if; end if -- [date of birth check]-- if v_length = 15 then select '19' | | substr (pairidcardReceiver 7 then select substr 6) into v_date from dual; elsif v_length = 18 then select substr (pairidcardPower7 Pie8) into v_date from dual; end if; v_isDate: = isDate (v_date); if not (v_isDate) then return-2; end if -- if v_length = 18 then v_sum: = (TO_NUMBER (SUBSTRB (p_idcard, 1,1)) + TO_NUMBER (SUBSTRB (p_idcard, 11,1) * 7 + (TO_NUMBER (p_idcard (p_idcard, 2,1)) + TO_NUMBER (SUBSTRB (p_idcard, 12)) )) * 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) )) * 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 (pairidcardMagne 18) then return 1; else return-4; end if; else return 1; end if;End Func_checkIdcard;/Show Err

Summary

The above is the oracle ID card check function introduced by the editor to you. I hope it will be helpful to you. If you have any questions, please leave a message for me. The editor will reply you in time. Thank you very much for your support to the website!

If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report