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

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/The_Thinnest/article/details/68942262


更新出生年月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) ;

展开阅读全文

根据18身份证15身份证输出省份性别和年龄

03-02

select case left(idcard,2) rnwhen '11' then '北京市'rnwhen '12' then '天津市'rnwhen '13' then '河北省'rnwhen '14' then '山西省'rnwhen '15' then '内蒙古自治区'rnwhen '21' then '辽宁省'rnwhen '22' then '吉林省'rnwhen '23' then '黑龙江省'rnwhen '31' then '上海市'rnwhen '32' then '江苏省'rnwhen '33' then '浙江省'rnwhen '34' then '安徽省'rnwhen '35' then '福建省'rnwhen '36' then '江西省'rnwhen '37' then '山东省'rnwhen '41' then '河南省'rnwhen '42' then '湖北省'rnwhen '43' then '湖南省'rnwhen '44' then '广东省'rnwhen '45' then '广西壮族自治区'rnwhen '46' then '海南省'rnwhen '50' then '重庆市'rnwhen '51' then '四川省'rnwhen '52' then '贵州省'rnwhen '53' then '云南省'rnwhen '54' then '西藏自治区'rnwhen '61' then '陕西省'rnwhen '62' then '甘肃省'rnwhen '63' then '青海省'rnwhen '64' then '宁夏回族自治区'rnwhen '65' then '新疆维吾尔自治区'rnwhen '71' then '台湾省'rnwhen '81' then '香港特别行政区'rnwhen '82' then '澳门特别行政区'rnelse '未知' rnend as 省份 ,rnrnyear(curdate())-if(length(idcard)=18,substring(idcard,7,4),if(length(idcard)=15,concat('19',substring(idcard,7,2)),null)) as 年龄, rnrncase if(length(idcard)=18, cast(substring(idcard,17,1) as UNSIGNED)%2, if(length(idcard)=15,cast(substring(idcard,15,1) as UNSIGNED)%2,3)) rnwhen 1 then '男'rnwhen 0 then '女'rnelse '未知'rnend as 性别rnrnFROM `user`rnrnrn想根据18位身份证和15位身份证查询身份、年龄、性别,看网上写的这个,发现只能输出最后一行,其余的年龄输出为Null,性别输出为Null,省份能够完全输出,还有2002年出生的,年龄怎么输出。求解决办法。测试数据rnrnrn421224198508136425rn429006199207163644rn429006199608123652rn429006199808163664rn429006199608163694rn429006960816369rn429006200208163695rn429006020816369rn 论坛

没有更多推荐了,返回首页