您的位置:首页 > 数据库 > Oracle

oracle解析身份证号码.sql

2017-01-05 23:05 1311 查看
-- 创建一个表
drop table employee ;create table employee (
NO number(4) primary key not null  ,
NAME varchar(60) not null ,
SN number(18)
);comment on table employee
is '员工信息表';
comment on column employee.NO
is '工号';
comment on column employee.NAME
is '姓名';
comment on column employee.SN
is '身份证号';
--插入数据
insert into employee (NO, NAME, SN) values (100, '王盼东', 410482199012052339) ;
insert into employee (NO, NAME, SN) values (101, '张三', 110226198501272116) ;
insert into employee (NO, NAME, SN) values (102, '李四', 410050197712452649) ;
insert into employee (NO, NAME, SN) values (103, '王五', 410110198911152468) ;
insert into employee (NO, NAME, SN) values (104, '刘六', 110105199401051599) ;
insert into employee (NO, NAME, SN) values (105, '赵七', 440100200012311224) ;--搜索并解析
select distinct
case substr(SN,1,2)
  when '41'
    then '河南'
  when '11'
    then '北京'
  when '44'
    then '广东'
      end 省份,     
case substr(SN,1,2)
  when '41'
    then case substr(SN,3,4)
      when '0110'
        then '漯河'
      when '0482'
        then '汝州'
      when '0050'
      then '安阳'
          end
  when '11'
    then case substr(SN,3,4)
     when '0226'
        then '平谷'
      when '0105'
        then '朝阳'
          end
 when '44'
    then case substr(SN,3,4)
     when '0100'
        then '广州'
      when '0302'
        then '盐田'
          end
          end 地市,
case
  when substr(SN,17,1)  in ('1','3','5','7','9')
    then '男'
  when substr(SN,17,1)  in ('0','2','4','6','8')
    then '女'
      end 性别,
      NAME  "姓名",to_date(substr(SN,7,8),'YYYY/MM/DD') "出生日期"
 from employee where NO = (&NO);    
     
     
    
      
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: