create or replace function ager (beg_date date) return varchar2 is
total_age number;
remainder number;
years number;
months number;
days number;
hours number;
minutes number;
seconds number;
year_txt varchar2(20);
month_txt varchar2(20);
day_txt varchar2(20);
hour_txt varchar2(20);
minute_txt varchar2(20);
second_txt varchar2(20);
beg_plus_yrs date;
beg_plus_yrs_mos date;
beg_plus_yrs_mos_dys date;
beg_plus_yrs_mos_dys_hrs date;
beg_plus_yrs_mos_dys_hrs_mins date;
begin
total_age := months_between(sysdate,beg_date);
years := trunc(total_age/12);
beg_plus_yrs := add_months(beg_date,years*12);
months := trunc(months_between(sysdate,beg_plus_yrs));
beg_plus_yrs_mos := add_months(beg_plus_yrs,months);
days := trunc(sysdate-beg_plus_yrs_mos);
beg_plus_yrs_mos_dys := beg_plus_yrs_mos+days;
hours := trunc((sysdate-beg_plus_yrs_mos_dys)*24);
beg_plus_yrs_mos_dys_hrs := beg_plus_yrs_mos_dys + (hours/24);
minutes := trunc((sysdate-beg_plus_yrs_mos_dys_hrs)*24*60);
beg_plus_yrs_mos_dys_hrs_mins := beg_plus_yrs_mos_dys_hrs+(minutes/24/60);
seconds := trunc((sysdate-beg_plus_yrs_mos_dys_hrs_mins)*24*60*60);
if years = 1 then year_txt := ' year, '; else year_txt := ' years, '; end if;
if months = 1 then month_txt := ' month, '; else month_txt := ' months, '; end if;
if days = 1 then day_txt := ' day, '; else day_txt := ' days, '; end if;
if hours = 1 then hour_txt := ' hour, '; else hour_txt := ' hours, '; end if;
if minutes = 1 then minute_txt := ' minute, '; else minute_txt := ' minutes, '; end if;
if seconds = 1 then second_txt := ' second. '; else second_txt := ' seconds.'; end if;
return years||year_txt||months||month_txt||days||day_txt||hours||hour_txt
||minutes||minute_txt||seconds||second_txt;
end;
/
Function created.