create or replace FUNCTION           ft_calretrydtm ( as_coopid char , adtm_birth date ) return date
is
ldtm_retry date;
begin
	if as_coopid is null or adtm_birth is null then
		return null;
	end if;

  select last_day( to_date( '01/' || trim( to_char( retry_month , '00' ) ) || '/' || to_char( retry_date , 'yyyy' ) , 'dd/mm/yyyy' ) ) as retry_date 
  into ldtm_retry
  from(
        select ( retry_month - 1 ) as retry_month ,
        ( case when to_char( adtm_birth , 'mm' ) < nvl( retry_month , 0 ) then add_months( adtm_birth , 12 * nvl( retry_age , 0 ) ) else add_months( adtm_birth , 12 * ( nvl( retry_age , 0 ) + 1 ) ) end ) as retry_date
        from cmcoopconstant
        where coop_no = as_coopid
      ) ;
  
	return ldtm_retry;
end ;
/
