mysql根據身份證提取生日和性別
阿新 • • 發佈:2018-11-09
update security_user set sex='女' where id in ( select a.id from ( SELECT id , SUBSTR(ID_CARD,7,8),SUBSTR(ID_CARD,17,1),ID_CARD,birthday,sex from security_user where LENGTH(ID_CARD) =18 and sex is null and data_state=1 and (SUBSTR(ID_CARD,17,1))%2=0) a );
SUBSTR(ID_CARD,17,1) 截取出判斷性別的數字
update security_user set sex='男' where id in ( select a.id from ( SELECT id , SUBSTR(ID_CARD,7,8),SUBSTR(ID_CARD,17,1),ID_CARD,birthday,sex from security_user where LENGTH(ID_CARD) =18 and sex is null and data_state=1 and (SUBSTR(ID_CARD,17,1))%2 !=0) a );
update security_user set birthday= CONCAT(left(birthday,7),'-',right(birthday,LENGTH(birthday)-7)) where LENGTH(birthday)=9 ;
SUBSTR(ID_CARD,17,1) 截取出判斷性別的數字
update security_user set sex='男' where id in ( select a.id from ( SELECT id , SUBSTR(ID_CARD,7,8),SUBSTR(ID_CARD,17,1),ID_CARD,birthday,sex from security_user where LENGTH(ID_CARD) =18 and sex is null and data_state=1 and (SUBSTR(ID_CARD,17,1))%2 !=0) a );
update security_user set birthday=SUBSTR(ID_CARD,7,8) where LENGTH(ID_CARD) =18 and birthday is null ;
update security_user set birthday= CONCAT(left(birthday,4),'-',right(birthday,LENGTH(birthday)-4)) where LENGTH(birthday)=8 ;update security_user set birthday= CONCAT(left(birthday,7),'-',right(birthday,LENGTH(birthday)-7)) where LENGTH(birthday)=9 ;