当前位置:首页 » 编程语言 » sql身份证验证
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql身份证验证

发布时间: 2022-09-02 02:53:33

sql 语句 验证身份证号码

帮你搜了一下,参考参考。

主要验证SQL数据库中已输入的15位 及18位 身份证号码的位数、出生年月日是否正确,
可以过滤出大部分的输入错误。

or (len(身份证号)=18 and (Substring(身份证号,7,2)<'19' or Substring(身份证号,7,2)>'20'
or (Substring(身份证号,11,2)>12)
or (Substring(身份证号,11,2) in (01,03,05,07,08,10,12) and Substring(身份证号,13,2)>31)
or (Substring(身份证号,11,2) in (04,06,09,11) and Substring(身份证号,13,2)>30)
or (Substring(身份证号,11,2)=02 and Substring(身份证号,13,2)>29)))
---------------------- 下面是针对 15位 及18位 身份证号码性别的验证语句 ------------------

-- Access 不支持 Substring 查询,可以替换为 mid 查询。
select 序号,姓名,身份证号,性别
from 身份表
where (((len(身份证号)=15) and (Substring(身份证号,15,1) in (1,3,5,7,9)) and 性别<>'男')
or ((len(身份证号)=15) and (Substring(身份证号,15,1) in (2,4,6,8,0)) and 性别<>'女'))
or (((len(身份证号)=18) and (Substring(身份证号,17,1) in (1,3,5,7,9)) and 性别<>'男')
or ((len(身份证号)=18) and (Substring(身份证号,17,1) in (2,4,6,8,0)) and 性别<>'女'))

---------------------- 下面是针对 15位 及18位 身份证号码位数与出生年月日的验证 ------------------

-- Access 不支持 Substring 查询,可以替换为 mid 查询。

select 序号,姓名,身份证号,性别
from 身份表
where (len(身份证号)<>15 and len(身份证号)<>18)
or (len(身份证号)=15 and ((Substring(身份证号,9,2)>12)
or (Substring(身份证号,11,2) > 31)
or (Substring(身份证号,9,2) in (01,03,05,07,08,10,12) and Substring(身份证号,11,2)>31)
or (Substring(身份证号,9,2) in (04,06,09,11) and Substring(身份证号,11,2)>30)
or (Substring(身份证号,9,2)=02 and Substring(身份证号,11,2)>29)))

⑵ 如何通过SQL语言检索身份证号的尾号验证

不是很理解你的意思、、检索尾号为1

select*fromtablewhereidcardlike'%1'

⑶ 如何用sql语言比对两张表中是否有重复身份证号

select id

from table_name

group by id

having count(*)>1

select [业务_低保$].[序号], [业务_低保$].[姓名], [业务_低保$].[身份证号], [业务_低保$].[银行卡号]

from [业务_低保$]

where [业务_低保$].[身份证号] in(

select [业务_低保$].[身份证号]

from [业务_低保$]

group by [业务_低保$].[身份证号]

功能

SQL具有数据定义、数据操纵和数据控制的功能。

1、SQL数据定义功能:能够定义数据库的三级模式结构,即外模式、全局模式和内模式结构。在SQL中,外模式又叫做视图(View),全局模式简称模式(Schema),内模式由系统根据数据库模式自动实现,一般无需用户过问。

2、SQL数据操纵功能:包括对基本表和视图的数据插入、删除和修改,特别是具有很强的数据查询功能。

⑷ sql中判断身份证号码的出生年月是否正确合法

好办呀 oracle-sql
select substr(身份证号,7,8) from al;

这样取出的就是出生年月日了

⑸ SQL中判断身份证对与否

我曾写过完整的身份证校验过程,
但是是VB的和VB.net的,如果你要可能给你,如果你要SQL的,我就翻译一下.

下面只校验日期

函数如下
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

CREATE FUNCTION CheckSNID ( @snid nvarchar(20))
RETURNS bit AS
BEGIN
declare @b bit

set @b = 0

if len(@snid)<>15 and len(@snid)<>18
goto ext

if len(@snid)=15
set @snid = left(@snid,6) + '19'+ right(@snid,9)

declare @y nvarchar(4),@m nvarchar(2) ,@d nvarchar(2)
set @y = substring(@snid,7,4)
set @m = substring(@snid,11,2)
set @d = substring(@snid,13,2)
declare @x nvarchar(10)

set @x = @y +'-'+@m+'-'+@d
if isdate(@x) =1
set @b=1

ext:
return @b
END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

select * from sb03 where dbo.CheckSNID (gr02) =1

⑹ 求SQL加入身份证号验证第18位的方法

身份证号码是每一个公民终身不变的号码,不要查询使用他人的身份号码,请使用自己的身份号码,否则会负法律责任。

⑺ sql sever 2008r2 中如何批量判断身份证真假

--建议你做成一个自定义函数,然后再调用
--区域编码的验证,你得有csounty_sar这个表才行,所以下面的代码,我去掉了这个
Declare@pspt_idVarchar(18)='52212019880722042X'
Select
case
/*判断身份证号码是否为18位*/
whenlen(@pspt_id)<>'18'then'身份证号码位数不对'
/*判断身份证号码前17位是否含除数字外的字符*/
whenISNUMERIC(substring(@pspt_id,1,17))=0then'身份证号码前17位格式不正确'
/*判断身份证的年份是否在合理范围内*/
whensubstring(@pspt_id,7,4)notbetween'1900'and'2014'then'身份证年份错误'
/*判断身份证的月份是否在合理范围内*/
whensubstring(@pspt_id,11,2)notbetween'01'and'12'then'身份证月份错误'
/*判断身份证日期是否在合理范围内*/
whenisdate(substring(@pspt_id,7,8))=0then'身份证日期错误'
/*判断身份证号码的第18位是否符合验证规则*/
when
(
substring(@pspt_id,1,1)*7+
substring(@pspt_id,2,1)*9+
substring(@pspt_id,3,1)*10+
substring(@pspt_id,4,1)*5+
substring(@pspt_id,5,1)*8+
substring(@pspt_id,6,1)*4+
substring(@pspt_id,7,1)*2+
substring(@pspt_id,8,1)*1+
substring(@pspt_id,9,1)*6+
substring(@pspt_id,10,1)*3+
substring(@pspt_id,11,1)*7+
substring(@pspt_id,12,1)*9+
substring(@pspt_id,13,1)*10+
substring(@pspt_id,14,1)*5+
substring(@pspt_id,15,1)*8+
substring(@pspt_id,16,1)*4+
substring(@pspt_id,17,1)*2
)%11
<>
(
case
whensubstring(@pspt_id,18,1)='1'then'0'
whensubstring(@pspt_id,18,1)='0'then'1'
whensubstring(@pspt_id,18,1)in('X','x')then'2'
whensubstring(@pspt_id,18,1)='9'then'3'
whensubstring(@pspt_id,18,1)='8'then'4'
whensubstring(@pspt_id,18,1)='7'then'5'
whensubstring(@pspt_id,18,1)='6'then'6'
whensubstring(@pspt_id,18,1)='5'then'7'
whensubstring(@pspt_id,18,1)='4'then'8'
whensubstring(@pspt_id,18,1)='3'then'9'
whensubstring(@pspt_id,18,1)='2'then'10'
end
)
then'身份证验证错误'Else'正确'EndAs结果

⑻ 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中检查身份证是否正确

select 字段1, 字段2
from t
where 字段=‘身份证号’;
有就是真的,没有就是假的啊!只不过具体问题具体分析

⑽ SQL 中身份证编码与出生日期验证

根据身份证号验证出生日期:

alter table 你的表--修改表
/*添加约束 要么删掉你之前的生日约束 要么把
约束开始到结束复制到你的约束里再改*/
add constraint CK_生日 check(

--约束开始
convert(datetime,replace(stuff(stuff(right (left(char之类类型的18位的身份证号,14),8),5,0,'-'),8,0,'-'),'0',''))=生日字段
--约束结束

)

最后只要把中文替换掉就可以了