您现在的位置是:群英 > 数据库 > 关系型数据库
Oracle中如何依据身份证号得到信息
Admin发表于 2022-07-13 17:42:541049 次浏览
这篇文章主要给大家介绍“Oracle中如何依据身份证号得到信息”的相关知识,下文通过实际案例向大家展示操作过程,内容简单清晰,易于学习,有这方面学习需要的朋友可以参考,希望这篇“Oracle中如何依据身份证号得到信息”文章能对大家有所帮助。


1、通过身份证号查询所在省市

SELECT
count(*) as total,
 case substr(t.CERTNO,0,2)
  when '11' then '北京市'
  when '12' then '天津市'
  when '13' then '河北省'
  when '14' then '山西省'
  when '15' then '内蒙古自治区'
  when '21' then '辽宁省'
  when '22' then '吉林省'
  when '23' then '黑龙江省'
  when '31' then '上海市'
  when '32' then '江苏省'
  when '33' then '浙江省'
  when '34' then '安徽省'
  when '35' then '福建省'
  when '36' then '江西省'
  when '37' then '山东省'
  when '41' then '河南省'
  when '42' then '湖北省'
  when '43' then '湖南省'
  when '44' then '广东省'
  when '45' then '广西壮族自治区'
  when '46' then '海南省'
  when '50' then '重庆市'
  when '51' then '四川省'
  when '52' then '贵州省'
  when '53' then '云南省'
  when '54' then '西藏自治区'
  when '61' then '陕西省'
  when '62' then '甘肃省'
  when '63' then '青海省'
  when '64' then '宁夏回族自治区'
  when '65' then '新疆维吾尔自治区'
  when '71' then '台湾省'
  when '81' then '香港特别行政区'
  when '82' then '澳门特别行政区'
  else '未知'
  end AS province
 FROM uip_bjt_userinfo t 
 group by case substr(t.CERTNO,0,2)
    when '11' then '北京市'
    when '12' then '天津市'
    when '13' then '河北省'
    when '14' then '山西省'
    when '15' then '内蒙古自治区'
    when '21' then '辽宁省'
    when '22' then '吉林省'
    when '23' then '黑龙江省'
    when '31' then '上海市'
    when '32' then '江苏省'
    when '33' then '浙江省'
    when '34' then '安徽省'
    when '35' then '福建省'
    when '36' then '江西省'
    when '37' then '山东省'
    when '41' then '河南省'
    when '42' then '湖北省'
    when '43' then '湖南省'
    when '44' then '广东省'
    when '45' then '广西壮族自治区'
    when '46' then '海南省'
    when '50' then '重庆市'
    when '51' then '四川省'
    when '52' then '贵州省'
    when '53' then '云南省'
    when '54' then '西藏自治区'
    when '61' then '陕西省'
    when '62' then '甘肃省'
    when '63' then '青海省'
    when '64' then '宁夏回族自治区'
    when '65' then '新疆维吾尔自治区'
    when '71' then '台湾省'
    when '81' then '香港特别行政区'
    when '82' then '澳门特别行政区'
    else '未知'end order by province desc

2、通过身份证号得到性别(第17位为奇数为男,偶数为女)

select 
  decode(mod(to_number(substr(t.useridcardnum, 17, 1)), 2),0,'女','男') as sex
 from uip_ca_userinfo t

3、通过身份证号得到年龄

select to_char(sysdate, 'yyyy') - substr(t.useridcardnum, 7, 4) as age from uip_ca_userinfo t

4、通过身份证号统计所在年龄段的人数

select count(t.id),
  case
   when to_char(sysdate, 'yyyy') - substr(t.useridcardnum, 7, 4) between 1 and 20 then
   '1-20岁'
   when to_char(sysdate, 'yyyy') - substr(t.useridcardnum, 7, 4) between 21 and 30 then
   '21-30岁'
   when to_char(sysdate, 'yyyy') - substr(t.useridcardnum, 7, 4) between 31 and 40 then
   '31-40岁'
   when to_char(sysdate, 'yyyy') - substr(t.useridcardnum, 7, 4) between 41 and 50 then
   '41-50岁'
   else
   '50岁以上'
  end as 年龄段
 from uip_ca_userinfo t
 group by case
   when to_char(sysdate, 'yyyy') - substr(t.useridcardnum, 7, 4) between 1 and 20 then
    '1-20岁'
   when to_char(sysdate, 'yyyy') - substr(t.useridcardnum, 7, 4) between 21 and 30 then
    '21-30岁'
   when to_char(sysdate, 'yyyy') - substr(t.useridcardnum, 7, 4) between 31 and 40 then
    '31-40岁'
   when to_char(sysdate, 'yyyy') - substr(t.useridcardnum, 7, 4) between 41 and 50 then
    '41-50岁'
   else
    '50岁以上'
   end
 order by 年龄段 asc

5、通过身份证号统计男女数量

select count(t.id),
  decode(mod(to_number(substr(t.useridcardnum, 17, 1)), 2),0,'女','男') as sex
 from uip_ca_userinfo t
 where to_char(sysdate, 'yyyy') - substr(t.useridcardnum, 7, 4) between 1 and 26
 group by decode(mod(to_number(substr(t.useridcardnum, 17, 1)), 2),0,'女','男')

总结


以上就是关于Oracle中如何依据身份证号得到信息的介绍,本文内容仅供参考,有需要的朋友可以借鉴了解看看,希望对大家学习或工作,想要了解更多欢迎关注群英网络,小编每天都会为大家更新不同的知识。

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。

相关信息推荐
2022-05-11 11:58:59 
摘要:方法:1、利用“trim(translate(column,'0123456789',' ')) is NULL;”判断数据是否是数字;2、利用“regexp_like(column,'^[0-9]+[0-9]$');”判断数据是否是数字。
2022-07-13 17:21:00 
摘要:这篇文章主要介绍了Oracle 遍历游标的四种方式汇总(for、fetch、while、BULK COLLECT),帮助大家更好的理解和使用Oracle数据库,感兴趣的朋友可以了解下
2022-05-18 17:26:00 
摘要:oracle不是应用软件,oracle是系统软件;系统软件主要包括操作系统、数据库管理系统和服务程序等,而应用软件是为完成某种特定工作,解决一些具体问题而编写的程序,oracle是甲骨文公司的一款关系数据库管理系统,属于系统软件。
群英网络助力开启安全的云计算之旅
立即注册,领取新人大礼包
  • 联系我们
  • 24小时售后:4006784567
  • 24小时TEL :0668-2555666
  • 售前咨询TEL:400-678-4567

  • 官方微信

    官方微信
Copyright  ©  QY  Network  Company  Ltd. All  Rights  Reserved. 2003-2019  群英网络  版权所有   茂名市群英网络有限公司
增值电信经营许可证 : B1.B2-20140078   粤ICP备09006778号
免费拨打  400-678-4567
免费拨打  400-678-4567 免费拨打 400-678-4567 或 0668-2555555
微信公众号
返回顶部
返回顶部 返回顶部