Author Topic: sf_week_day_order  (Read 1505 times)

Prakash

  • Newbie
  • *
  • Posts: 17
    • View Profile
sf_week_day_order
« 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)
RETURN NUMBER
AUTHID current_user
IS
/******************************************************************************
   NAME:       sf_week_day_order
   PURPOSE:    Function to return the order of the day in a week SUN - WED - SAT

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

   NOTES:

   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)

******************************************************************************/
BEGIN
   IF weekday = 'SUNDAY'
   THEN
      RETURN 1;
   ELSIF weekday = 'MONDAY'
   THEN
      RETURN 2;
   ELSIF weekday = 'TUESDAY'
   THEN
      RETURN 3;
   ELSIF weekday = 'WEDNESDAY'
   THEN
      RETURN 4;
   ELSIF weekday = 'THURSDAY'
   THEN
      RETURN 5;
   ELSIF weekday = 'FRIDAY'
   THEN
      RETURN 6;
   ELSIF weekday = 'SATURDAY'
   THEN
      RETURN 7;
   END IF;
END sf_week_day_order;
« Last Edit: September 25, 2013, 06:56:23 PM by Mike »


Mike

  • Administrator
  • Hero Member
  • *****
  • Posts: 2008
    • View Profile
Re: sf_week_day_order
« Reply #1 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.