Saturday, May 25, 2013

Timdiff

/* Formatted On 2012/02/04 16:30 (Formatter Plus V4.8.8) */
Create Or Replace Function Timdiff(Date1 In Varchar,Time1 In Varchar, Time2 In Varchar)
   Return Varchar
Is
   Diff Varchar(30);
Begin
   If Time1 Is Null Then
      Dbms_Output.Put_Line ('Time1 Null Case This is Time1:'||Time1);
      Return '--';
   End If;
   If Time2 Is Null Then
      Dbms_Output.Put_Line ('Time2  Null Case This is Time2:'||Time2);
      Return '--';
   End If;                  
   If Time1 Is Not Null And Time2 Is Not Null
   Then
      Begin
      Dbms_Output.Put_Line(' Not Null Case :This is Time1:'||Time1||' & This is Time1:'||Time2||' And Date1:'||Date1);
         Select Distinct To_Char(Round(To_Number((To_Date(Decode(to_date(Date1),'', Sysdate,Date1) || ' '  || '' || Time1 || '','DD-mon-yyyy HH24MI')
                                                 -To_Date(Decode(to_date(Date1),'', Sysdate,Date1) || ' '  || '' || Time2 || '','DD-mon-yyyy HH24MI')
                                           )  * 1440
                                         )
                               )) Dos
         Into Diff From Dual;
         Dbms_Output.Put_Line('Times Difference in Mins : '||Diff);
         Return Diff;
      End;
     
   End If;
    Exception
       When No_Data_Found Then
       Raise_Application_Error (-2021,'manager not a valid employee');
End;
/

No comments:

Post a Comment