导航:首页 > 文档加密 > sql身份证号最后四位加密

sql身份证号最后四位加密

发布时间:2024-11-15 00:07:53

⑴ SQL函数验证身份证号码是否有效

SQL函数验证身份证号码是否有效
比如身份证号在C列,D2:
=IF(MID("10X98765432",MOD(SUM(MID(C2,{1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17},1)*2^(18-{1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17})),11)+1,1)=RIGHT(C2),"身份证正确","身份证错误")
数组公式,按CTRL+SHIFT+回车结束,下拉。

⑵ sql 语句 验证身份证号码

像这样写个视图就行了:

create View eVMutiCard
AS
Select a.Badge,a.Name,a.DepID,a.Compid,a.JobID,a.Status,a.EmpType,a.ReportTo,
b.Identification,
N'身份证长度不合常理' As Remark
From employee b
Where (Len(b.Identification) Not In (15,18)
And b.Identification Is Not Null )
Or b.Identification is Null
Union All
Select a.Badge,a.Name,a.DepID,a.Compid,a.JobID,a.Status,a.EmpType,a.ReportTo,
b.Identification,
N'身份证具有无效字符' As Remark
From employee b
Where Len(b.Identification) In (15,18)
And Isnumeric(Case Len(b.Identification) When 18 Then Substring(b.Identification,1,17)
Else b.Identification End) = 0
Union All
Select a.Badge,a.Name,a.DepID,a.Compid,a.JobID,a.Status,a.EmpType,a.ReportTo,
b.Identification,
N'身份证出生日期不合常理' As Remark
From employee b
Where Len(b.Identification) In (15,18)
And (IsDate(Case When Len(b.Identification)=15 Then '19'+Substring(b.Identification,7,2)+'-'+Substring(b.Identification,9,2)+'-'+Substring(b.Identification,11,2)
Else Substring(b.Identification,7,4)+'-'+Substring(b.Identification,11,2)+'-'+Substring(b.Identification,13,2)
End)=0
Or Not (
(Case When Len(b.Identification)=15 Then '19'+Substring(b.Identification,7,2)+'-'+Substring(b.Identification,9,2)+'-'+Substring(b.Identification,11,2)
Else Substring(b.Identification,7,4)+'-'+Substring(b.Identification,11,2)+'-'+Substring(b.Identification,13,2)
End) Between '1900-01-01' And '2079-06-06'))
Union All
Select a.Badge,a.Name,a.DepID,a.Compid,a.JobID,a.Status,a.EmpType,a.ReportTo,
b.Identification,
N'身份证校验位不正确(第18位与校验不符)' As Remark
From employee b
Where (Len(b.Identification) = 18
And substring(b.Identification,18,19) <> dbo.GetCheckIDCardCode(b.Identification)
And b.Identification Is Not Null)

其中跟据国家规定的计算公式,计算18位身份证检验位的dbo.GetCheckIDCardCode如下:

CREATE function GetCheckIDCardCode(@sfzh char(18))
returns char(1)
as
begin
declare @r varchar(2)
declare @i int
if len(@sfzh) <> 18
set @r = 0
else
set @i = cast(substring(@sfzh,1,1) as int) * 7
+cast(substring(@sfzh,2,1) as int) * 9
+cast(substring(@sfzh,3,1) as int) * 10
+cast(substring(@sfzh,4,1) as int) * 5
+cast(substring(@sfzh,5,1) as int) * 8
+cast(substring(@sfzh,6,1) as int) * 4
+cast(substring(@sfzh,7,1) as int) * 2
+cast(substring(@sfzh,8,1) as int) * 1
+cast(substring(@sfzh,9,1) as int) * 6
+cast(substring(@sfzh,10,1) as int) * 3
+cast(substring(@sfzh,11,1) as int) * 7
+cast(substring(@sfzh,12,1) as int) * 9
+cast(substring(@sfzh,13,1) as int) * 10
+cast(substring(@sfzh,14,1) as int) * 5
+cast(substring(@sfzh,15,1) as int) * 8
+cast(substring(@sfzh,16,1) as int) * 4
+cast(substring(@sfzh,17,1) as int) * 2
set @i = @i - @i/11 * 11
set @r = cast((case @i
when 0 then 1
when 1 then 0
when 2 then 11
when 3 then 9
when 4 then 8
when 5 then 7
when 6 then 6
when 7 then 5
when 8 then 4
when 9 then 3
when 10 then 2
else '' end) as char)

if (@r = 11) set @r='X'
else set @r = @r

set @r = '' + @r +''
return @r
end

⑶ 现有sql数据表其中包含很多身份证号,将该身份证进行检索,根据地区、年龄段等分类统计

不用正则表达式,用substr就可以了
地区是前六位,你可以上网查一下含义,统计可以取substr(id,1,6)
生日是第七位开始的八位数substr(id,7,8)

阅读全文

与sql身份证号最后四位加密相关的资料

热点内容
python适合什么编译器 浏览:842
双强力夹文件夹使用方法 浏览:328
程序员瑜伽教学 浏览:807
python网页分析工具 浏览:687
服务器如何手动关机 浏览:47
火柴盒app什么都加载不出来 浏览:321
为什么腾讯视频app不显示缓存列表 浏览:408
android网络服务器 浏览:972
618程序员男扮女装 浏览:995
框架梁为什么是非加密区 浏览:993
什么app能把删了的照片恢复 浏览:360
公务员说程序员工资 浏览:400
怎样设置自己手机号码加密 浏览:700
服务器怎么设置登录地址 浏览:997
日本监控摄像头用什么APP 浏览:58
株洲歪胡子游戏源码 浏览:140
朔源码燕窝会假吗 浏览:279
php是否支持gd 浏览:925
旅游查攻略下载什么app 浏览:774
ps存储不在原始文件夹 浏览:37