oracle根据身份证更新出生日期(15位与18位身份证都可)


更新出生年月sql 语句如下:


update test_table a set a.csrq=
case 
       when length(a.sfzh)=18 then to_date(substr(a.sfzh,7,8),'yyyy-MM-dd') 
       when  length(a.sfzh)=15 then to_date(('19'||substr(a.sfzh,7,6)),'yyyy-MM-dd') 
end ;


更新年龄sql如下(因有不规范身份证,所以最后条件加上长度验证):

 update kjzl_oldperson_base a set a.nl = case when length(a.sfzh)=18 then (to_char(sysdate,'yyyy')-substr(a.sfzh,7,4)) 
when  length(a.sfzh)=15 then (to_char(sysdate,'yyyy')-('19'||substr(a.sfzh,7,2))) end
      where a.lrid in (
             select   t3.lrid from KJZL_VIEW_OLDBASET t3,
             KJZL_BAILOUT_SIGN_INFO b left join KJZL_DEVICE c on b.signid = c.signid where t3.lrid = b.lrid 
           and b.jjjzqyywzt = '2' and length(t3.sj)=11
      ) and length(a.sfzh) in (15,18) ;

你可能感兴趣的:(oracle,日期)