Create Or Replace Function Ft_Calage( Adtm_From Date , Adtm_To Date , Ai_Option Number ) Return Varchar2
Is
Ldc_Age	Number(15,10);
Ls_Year Varchar2(5);
Ls_Mth	Varchar2(5);
Ls_Day  Varchar2(5);
Ls_Age 	Varchar2(10);
Begin
	If Adtm_From Is Null Then
		Return '0.00';
	End If;
	If Adtm_To Is Null Then
		Return '0.00';
	End If;
	Select Months_Between( Adtm_To , Adtm_From ) 
	Into Ldc_Age
	From Dual;
  
  Case Ai_Option
  When 4 Then
    /*yy.mm Trunc Day*/
    Ls_Year	:= To_Char(Trunc( Ldc_Age - Mod( Ldc_Age , 12 ) , 0 )/12);
    Ls_Mth	:= To_Char(Trunc( Mod( Ldc_Age , 12 ), 0 ));
    Ls_Age	:= Ls_Year || '.' || Lpad(Ls_Mth,2 ,'0' );
  When 8 Then
    /*Period Trunc Mth*/
    Ls_Age  := To_Char(Trunc( Ldc_Age ) );
  When 9 Then
    /*Period Round Mth*/
    Ls_Age  := To_Char(Round( Ldc_Age ) );
  When 10 Then
    /*Period Ceiling Mth*/
    Ls_Age  := To_Char(Ceil( Ldc_Age ) );
  Else
    Return '0.00';
  End Case;
  
  Return Trim(Ls_Age);
  
End ;
/