General Category => PSOUG => Topic started by: Prakash on September 25, 2013, 03:48:01 PM

Title: sf_week_day_order
Post by: Prakash on September 25, 2013, 03:48:01 PM
Is there an automated function or procedure that gives the day of the week based on day and sorts the results by week days like SUN- MON - TUE - WED - THU - FRI - SAT.

I wrote this below function that may help return an order for the passed in day

Code: [Select]
CREATE OR REPLACE FUNCTION sf_week_day_order (weekday IN VARCHAR2)
AUTHID current_user
   NAME:       sf_week_day_order
   PURPOSE:    Function to return the order of the day in a week SUN - WED - SAT

   Ver        Date        Author           Description
   ---------  ----------  ---------------  ------------------------------------
   1.0        9/12/2013   prakash.gumudavelly       1. Created this procedure.


   Automatically available Auto Replace Keywords:
      Object Name:     sf_week_day_order
      Sysdate:         9/12/2013
      Date and Time:   9/12/2013, 10:57:46 AM, and 9/12/2013 10:57:46 AM
      Username:        prakash.gumudavelly (set in TOAD Options, Procedure Editor)
      Table Name:       (set in the "New PL/SQL Object" dialog)

   IF weekday = 'SUNDAY'
      RETURN 1;
   ELSIF weekday = 'MONDAY'
      RETURN 2;
   ELSIF weekday = 'TUESDAY'
      RETURN 3;
   ELSIF weekday = 'WEDNESDAY'
      RETURN 4;
   ELSIF weekday = 'THURSDAY'
      RETURN 5;
   ELSIF weekday = 'FRIDAY'
      RETURN 6;
   ELSIF weekday = 'SATURDAY'
      RETURN 7;
   END IF;
END sf_week_day_order;
Title: Re: sf_week_day_order
Post by: Mike on September 25, 2013, 06:58:02 PM
Great stuff, Prakash! I'm sure this will come in hand for lots of people. :)

I'll add it to the code library ( as soon as I get a chance.