update 員工表 set 身份證號=
substring(身份證號,1,6)+'18'+substring(身份證號,7,9)+
substring('10x98765432',
(cast(substring(身份證號, 1,1) as int)*7
+cast(substring(身份證號, 2,1) as int)*9
+cast(substring(身份證號, 3,1) as int)*10
+cast(substring(身份證號, 4,1) as int)*5
+cast(substring(身份證號, 5,1) as int)*8
+cast(substring(身份證號, 6,1) as int)*4
+1*2
+8*1
+cast(substring(身份證號, 7,1) as int)*6
+cast(substring(身份證號, 8,1) as int)*3
+cast(substring(身份證號, 9,1) as int)*7
+cast(substring(身份證號,10,1) as int)*9
+cast(substring(身份證號,11,1) as int)*10
+cast(substring(身份證號,12,1) as int)*5
+cast(substring(身份證號,13,1) as int)*8
+cast(substring(身份證號,14,1) as int)*4
+cast(substring(身份證號,15,1) as int)*2
)% 11 + 1, 1)
where len(身份證號)=15 and substring(身份證號,13,3) in ('999','998','997','996')
-- 15位身份證號公升級為18位,適用於19xx年出生的公民
update 員工表 set 身份證號=
substring(身份證號,1,6)+'19'+substring(身份證號,7,9)+
substring('10x98765432',
(cast(substring(身份證號, 1,1) as int)*7
+cast(substring(身份證號, 2,1) as int)*9
+cast(substring(身份證號, 3,1) as int)*10
+cast(substring(身份證號, 4,1) as int)*5
+cast(substring(身份證號, 5,1) as int)*8
+cast(substring(身份證號, 6,1) as int)*4
+1*2
+9*1
+cast(substring(身份證號, 7,1) as int)*6
+cast(substring(身份證號, 8,1) as int)*3
+cast(substring(身份證號, 9,1) as int)*7
+cast(substring(身份證號,10,1) as int)*9
+cast(substring(身份證號,11,1) as int)*10
+cast(substring(身份證號,12,1) as int)*5
+cast(substring(身份證號,13,1) as int)*8
+cast(substring(身份證號,14,1) as int)*4
+cast(substring(身份證號,15,1) as int)*2
)% 11 + 1, 1)
where len(身份證號)=15 and substring(身份證號,13,3) not in ('999','998','997','996')
PHP校驗15位和18位身份證號
看新公司框架原始碼的時候,發現了這個功能,於是搜尋一番並封裝了一下身份證號校驗的類。目前大家的身份證號大多是18位的,當然,也不排除有些老人的身份證號是15位的。如果強制要求是18位的話,會比較好,因為15位的身份證號沒有校驗碼,可以說,只要了解大概結構,隨手都可以造出一系列身份證號碼來。當然,如果...
身份證號 15位與18位間的轉換
開始 15位到18位的身份證號轉換 身份證號碼由十七位數字本體碼和一位校驗碼組成,排列順序從左至右依次為 六位數字址碼 八位數字的出生日期碼 三位數字的順序碼和一位數字的校驗碼 public string change18id string id15 if id15.length 15 char a...
15位身份證號的校驗
驗證15位身份證的合法性,該方法驗證不準確,最好是將15轉為18位後再判斷,該類中已提供。param idcard return public boolean isvalidate15idcard string idcard 是否全都為數字 if isdigital idcard if flag 該...