通过身份证号用sql获取年龄和性别

阅读更多
sql如下:
--自己创建的列不能用where 条件查询 可以通过子查询完成 

select

pid,

name,

id_card,

registry_type,

registry_county,

registry_street,

registry_neighbor_committee,

employment_status,

employment_type,

job_type,

employment_difficulty,

unemployment,

trunc((to_char(sysdate, 'yyyyMMdd') - to_char(to_date(substr(ID_CARD,7,8),'yyyyMMdd'),'yyyyMMdd'))/10000) as age,

substr(ID_CARD,17,1) as sex

from T_PERSON_INFO

where age = 48

and id_card = '340223196805105119';

你可能感兴趣的:(sql,Oracle)