身份证号18位校验脚本

这篇文章详细描述了一个SQL查询,用于检查输入的身份证号码是否符合年月日规则,并验证校验码的计算方法,以确定其有效性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


set @identityno='53010219200508011x';
select
       case when substr(@identityno, 7, 4) not between '1900' and '2022' then '身份证年份校验不通过'
             when substr(@identityno, 11, 2) not between '01' and '12' then '身份证月份校验不通过'
             when substr(@identityno, 13, 2) not between '01' and '31' then '身份证日期校验不通过'
        when mod(
            (
                substr(@identityno, 1, 1) * 7 + substr(@identityno, 2, 1) * 9 + substr(@identityno, 3, 1) * 10 + substr(@identityno, 4, 1) * 5 + substr(@identityno, 5, 1) * 8 + substr(@identityno, 6, 1) * 4 + substr(@identityno, 7, 1) * 2 + substr(@identityno, 8, 1) * 1 + substr(@identityno, 9, 1) * 6 + substr(@identityno, 10, 1) * 3 + substr(@identityno, 11, 1) * 7 + substr(@identityno, 12, 1) * 9 + substr(@identityno, 13, 1) * 10 + substr(@identityno, 14, 1) * 5 + substr(@identityno, 15, 1) * 8 + substr(@identityno, 16, 1) * 4 + substr(@identityno, 17, 1) * 2
            ),
            11
        ) <> (
            case
                when substr(@identityno, 18, 1) = '1' then '0'
                when substr(@identityno, 18, 1) = '0' then '1'
                when substr(@identityno, 18, 1) in ('X', 'x') then '2'
                when substr(@identityno, 18, 1) = '9' then '3'
                when substr(@identityno, 18, 1) = '8' then '4'
                when substr(@identityno, 18, 1) = '7' then '5'
                when substr(@identityno, 18, 1) = '6' then '6'
                when substr(@identityno, 18, 1) = '5' then '7'
                when substr(@identityno, 18, 1) = '4' then '8'
                when substr(@identityno, 18, 1) = '3' then '9'
                when substr(@identityno, 18, 1) = '2' then '10'
            end
        ) then '身份证合法性校验不通过'
        else '有效身份证'
    end as ret
from dual


set @identityno='53010219200508011x';
select
       case when substr(@identityno, 7, 4) not between '1900' and '2022' then '身份证年份校验不通过'
			 when substr(@identityno, 11, 2) not between '01' and '12' then '身份证月份校验不通过'
			 when substr(@identityno, 13, 2) not between '01' and '31' then '身份证日期校验不通过'
        when mod(
            (
                substr(@identityno, 1, 1) * 7 + substr(@identityno, 2, 1) * 9 + substr(@identityno, 3, 1) * 10 + substr(@identityno, 4, 1) * 5 + substr(@identityno, 5, 1) * 8 + substr(@identityno, 6, 1) * 4 + substr(@identityno, 7, 1) * 2 + substr(@identityno, 8, 1) * 1 + substr(@identityno, 9, 1) * 6 + substr(@identityno, 10, 1) * 3 + substr(@identityno, 11, 1) * 7 + substr(@identityno, 12, 1) * 9 + substr(@identityno, 13, 1) * 10 + substr(@identityno, 14, 1) * 5 + substr(@identityno, 15, 1) * 8 + substr(@identityno, 16, 1) * 4 + substr(@identityno, 17, 1) * 2
            ),
            11
        ) <> (
            case
                when substr(@identityno, 18, 1) = '1' then '0'
                when substr(@identityno, 18, 1) = '0' then '1'
                when substr(@identityno, 18, 1) in ('X', 'x') then '2'
                when substr(@identityno, 18, 1) = '9' then '3'
                when substr(@identityno, 18, 1) = '8' then '4'
                when substr(@identityno, 18, 1) = '7' then '5'
                when substr(@identityno, 18, 1) = '6' then '6'
                when substr(@identityno, 18, 1) = '5' then '7'
                when substr(@identityno, 18, 1) = '4' then '8'
                when substr(@identityno, 18, 1) = '3' then '9'
                when substr(@identityno, 18, 1) = '2' then '10'
            end
        ) then '身份证合法性校验不通过'
        else '有效身份证'
    end as ret
from dual

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一凡888

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值