mysql根据身份证提取生日和性别

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012269637/article/details/80615230
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=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 ;

猜你喜欢

转载自blog.csdn.net/u012269637/article/details/80615230