18-digit ID card verification code sharing ID card verification bit calculation using SQL

Source: Internet
Author: User

Calculation Method of ID card verification code

1. Multiply the 17 digits of the previous ID card number by different coefficients. The number of I-bits is [2 ^ (18-i)] mod11. The coefficients from the first digit to the second digit are 7 9 10 5 8 4 2 1 6 3 7 9 10 8 4 2;

2. Add the result of multiplying the 17-digit number and the coefficient;

3. How much is the remainder by adding and dividing by 11 ?;

4. The remainder may only contain the 11 numbers 0 1 2 3 4 5 6 7 8 9 10. The numbers corresponding to the last ID card respectively are 1 0X9 8 7 6 5 4 3 2;

Copy codeThe Code is as follows:
With t as (select '34052419800101001x 'id from dual)
Select id
From t
Where exists (select 1
From dual connect by level <= length (id)-1 -- 17
Having mod (sum (substr (id, level, 1) * power (2,18-level), 11) =
Case substr (id,-1, 1)
When '1' then 0
When '0' then 1
When 'X' then 2
Else
12-substr (id,-1, 1)
End );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.