Oracle根据身份证计算出年龄的sql脚本

1、select to_char(sysdate, 'yyyy') - substr('610526199807067651', 7, 4) as age from dual;

 

 2、如果是表中有列 ,姓名、身份证没有年龄

--增加一列年龄

alter table TMP1 add  age nvarchar2(3);

update TMP1 set age=to_char(sysdate, 'yyyy') - substr(CERT_NUM, 7, 4) where cert_type=1;

--TMP1 表名

--CERT_NUM 身份证号码 列名

--cert_type 证件类型  1代表身份证

 

posted @ 2021-09-30 08:34  DBer  阅读(1793)  评论(0)    收藏  举报