--满周岁
select trunc(months_between(&edate, &sdate)/12) from dual; --不需要满周岁
select ceil(months_between(&edate, &sdate)/12) from dual;
select trunc(months_between(&edate, &sdate)/12) from dual; --不需要满周岁
select ceil(months_between(&edate, &sdate)/12) from dual;
bd_year number(4);
bd_month number(2);
bd_day number(2);
this_year number(4);
this_month number(2);
this_day number(2); Result number;
begin
bd_year := to_char(bdate, 'yyyy');
bd_month := to_char(bdate, 'mm');
bd_day := to_char(bdate, 'dd');
this_year := to_char(sysdate, 'yyyy');
this_month := to_char(sysdate, 'mm');
this_day := to_char(sysdate, 'dd'); result := this_year - bd_year + (this_month - bd_month) / 12 +
(this_day - bd_day) / 30.4375 / 12;
return(Result);
end get_age;
/
-- 随便写写,不知道有没有更好的方法。
select trunc(months_between(sysdate, '2006-05-06')/12) from dual;
直接就可以执行;通用的话,可以
select trunc(months_between(sysdate, to_date('2006-05-06','yyyy-mm-dd'))/12) from dual;
对传入的字符串转换一下格式