sql server
查询判断身份证号是18位的
select SUBSTRING(SUBSTRING(IDCard,7,8),1,4)+'-'+SUBSTRING(SUBSTRING(IDCard,7,8),5,2)+'-'+SUBSTRING(SUBSTRING(IDCard,7,8),7,2) from 表 where Birthday is null and LEN(IDCard)=18
修改
update 表set Birthday=SUBSTRING(SUBSTRING(IDCard,7,8),1,4)+'-'+SUBSTRING(SUBSTRING(IDCard,7,8),5,2)+'-'+SUBSTRING(SUBSTRING(IDCard,7,8),7,2) where Birthday is null and LEN(IDCard)=18
oracle
SELECT (SUBSTR(IdNumStr,7,8 )) FROM DUAL;
输出是年月日字符串。再转换为对应需要的时间格式,例YYYY-MM-DD
SELECT to_char(to_date((SUBSTR(IdNumStr,7,8 )),'yyyy-mm-dd'),'yyyy-mm-dd') FROM DUAL;
create function U_GET_BIRTH(IDNUM in varchar2) return varchar2 as begin --根据身份证号取得对应的出生年月日,并转换为对应的日期格式 return to_char(to_date((SUBSTR(IDNUM ,7,8 )),'yyyy-mm-dd'),'yyyy-mm-dd'); end;
标签:yyyy,mm,dd,IDCard,身份证号,SUBSTRING,sql,出生日期 From: https://www.cnblogs.com/qingjiawen/p/17819395.html