Date time calculation function : Utility Function « Function Procedure Packages « Oracle PL/SQL Tutorial






SQL>
SQL> CREATE OR REPLACE FUNCTION expiration_date (
  2      good_for_period_in IN INTERVAL YEAR TO MONTH
  3  )
  4      RETURN TIMESTAMP
  5  IS
  6     bad_month EXCEPTION;
  7     PRAGMA EXCEPTION_INIT (bad_month, -1839);
  8
  9     todays_date TIMESTAMP;
 10     result_date TIMESTAMP;
 11  BEGIN
 12     todays_date := TRUNC(SYSTIMESTAMP);
 13     LOOP
 14        BEGIN
 15           result_date := todays_date + good_for_period_in;
 16        EXCEPTION
 17           WHEN bad_month THEN
 18              todays_date := todays_date - INTERVAL '1' DAY;
 19           WHEN OTHERS THEN
 20              RAISE;
 21        END;
 22
 23        EXIT WHEN result_date IS NOT NULL;
 24     END LOOP;
 25     RETURN result_date;
 26  END;
 27  /

Function created.








27.26.Utility Function
27.26.1.Get nearest day
27.26.2.Compare date offset in a function
27.26.3.Create a procedure to count employees
27.26.4.To number or null
27.26.5.Removes all numeric digits from the string passed in.
27.26.6.Generic function utilizing dynamic SQL to return the number of rows in the specified table.
27.26.7.Get the Max date
27.26.8.String between function
27.26.9.Add day to month
27.26.10.Date time calculation function
27.26.11.Table Count function
27.26.12.Word count function
27.26.13.Define your own varchar to date function
27.26.14.Get the next business day
27.26.15.Format money
27.26.16.Date calculation: business days between
27.26.17.Convert Comma-separated values to table collection
27.26.18.Function to convert celsius to fahrenheit
27.26.19.Function to convert fahrenheit to celsius
27.26.20.Get circle area