溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Oracle如何實(shí)現(xiàn)按身份證號(hào)得到省市、性別、年齡

發(fā)布時(shí)間:2020-07-17 14:51:12 來(lái)源:億速云 閱讀:946 作者:小豬 欄目:數(shù)據(jù)庫(kù)

小編這次要給大家分享的是Oracle如何實(shí)現(xiàn)按身份證號(hào)得到省市、性別、年齡,文章內(nèi)容豐富,感興趣的小伙伴可以來(lái)了解一下,希望大家閱讀完這篇文章之后能夠有所收獲。

1、通過(guò)身份證號(hào)查詢所在省市

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 '內(nèi)蒙古自治區(qū)'
  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 '廣西壯族自治區(qū)'
  when '46' then '海南省'
  when '50' then '重慶市'
  when '51' then '四川省'
  when '52' then '貴州省'
  when '53' then '云南省'
  when '54' then '西藏自治區(qū)'
  when '61' then '陜西省'
  when '62' then '甘肅省'
  when '63' then '青海省'
  when '64' then '寧夏回族自治區(qū)'
  when '65' then '新疆維吾爾自治區(qū)'
  when '71' then '臺(tái)灣省'
  when '81' then '香港特別行政區(qū)'
  when '82' then '澳門特別行政區(qū)'
  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 '內(nèi)蒙古自治區(qū)'
    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 '廣西壯族自治區(qū)'
    when '46' then '海南省'
    when '50' then '重慶市'
    when '51' then '四川省'
    when '52' then '貴州省'
    when '53' then '云南省'
    when '54' then '西藏自治區(qū)'
    when '61' then '陜西省'
    when '62' then '甘肅省'
    when '63' then '青海省'
    when '64' then '寧夏回族自治區(qū)'
    when '65' then '新疆維吾爾自治區(qū)'
    when '71' then '臺(tái)灣省'
    when '81' then '香港特別行政區(qū)'
    when '82' then '澳門特別行政區(qū)'
    else '未知'end order by province desc

2、通過(guò)身份證號(hào)得到性別(第17位為奇數(shù)為男,偶數(shù)為女)

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

Oracle如何實(shí)現(xiàn)按身份證號(hào)得到省市、性別、年齡

3、通過(guò)身份證號(hào)得到年齡

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

Oracle如何實(shí)現(xiàn)按身份證號(hào)得到省市、性別、年齡

4、通過(guò)身份證號(hào)統(tǒng)計(jì)所在年齡段的人數(shù)

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

Oracle如何實(shí)現(xiàn)按身份證號(hào)得到省市、性別、年齡

5、通過(guò)身份證號(hào)統(tǒng)計(jì)男女?dāng)?shù)量

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如何實(shí)現(xiàn)按身份證號(hào)得到省市、性別、年齡

看完這篇關(guān)于Oracle如何實(shí)現(xiàn)按身份證號(hào)得到省市、性別、年齡的文章,如果覺(jué)得文章內(nèi)容寫得不錯(cuò)的話,可以把它分享出去給更多人看到。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI