您当前的位置:首页 > 计算机 > 软件应用 > 数据库 > Oracle

Oracle 通过身份证号获得年龄

时间:03-22来源:作者:点击数:

sqlserver

if len(@idcard) = 15 OR len(@idcard) = 18 
	begin
		set @var1=''
		if LEN(@idcard)=15
			begin
				set @var1 =SUBSTRING(@idcard,15,1)
				set @birthday='19' +SUBSTRING(@idcard,7,2)+'-' +SUBSTRING(@idcard,9,2) +'-' +SUBSTRING(@idcard,11,2)
			end
		else
			begin
				set @var1 =SUBSTRING(@idcard,17,1)
				set @birthday=SUBSTRING(@idcard,7,4) +'-' +SUBSTRING(@idcard,11,2) +'-' +SUBSTRING(@idcard,13,2)
			end

		set @age= round (( DATEDIFF(day,@birthday,getdate())/ 365),0)
	end

Oracle

if length(vcardid) = 15 OR length(vcardid) = 18 then
	begin
		if length(vcardid) = 18 then
			begin
				select TRUNC ((  sysdate- TO_DATE (SUBSTR (vcardid, 7, 8), 'yyyy-mm-dd') )/ 365) into v_card_nl from dual;
                select SUBSTR (vcardid, 7, 8)  into V_csrq from dual;--出生日期
			end;
		else
			begin
				select TRUNC ((  sysdate- TO_DATE ('19' || SUBSTR (vcardid, 7, 6), 'yyyy-mm-dd') )/ 365) into v_card_nl from dual;
			end;
		end if;
	end;
end if;
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门