您现在的位置是:网站首页> 编程资料编程资料
Oracle按身份证号得到省市、性别、年龄的示例代码_oracle_
2023-05-27
607人已围观
简介 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按身份证号得到省市、性别、年龄的示例代码的文章就介绍到这了,更多相关oracle 身份证号得到省市 性别 年龄内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
您可能感兴趣的文章:
相关内容
- Windows10安装Oracle19c数据库详细记录(图文详解)_oracle_
- Oracle dbf文件移动的方法_oracle_
- Oracle SQLPlus导出数据到csv文件的方法_oracle_
- Oracle用decode函数或CASE-WHEN实现自定义排序_oracle_
- ORACLE数据库逐步解决ORA-12541、ORA-01034和ORA-27101、ORA-00119和ORA00132的过程_oracle_
- Oracle数据库服务器修改操作系统时间的注意事项详解_oracle_
- oracle基本查询操作子查询用法实例分析_oracle_
- oracle基本查询用法入门示例_oracle_
- oracle 存储过程、函数和触发器用法实例详解_oracle_
- Oracle 管理员账号密码忘记的快速解决方法_oracle_
