| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Job to run first Wednesday
I know some solutions have already been posted. I will add this one however. Some of the examples posted have the drawback that they assume your NLS date language is English.
The formula below uses the fact that 1 January 2003 is a Wednesday.
The expression to find the first Wednesday of the month following test_date. If test_date is the first Wednesday of the month then the value returned is the first Wednesday of the following month.
decode (sign (trunc (test_date)
proof of concept
SQL> column sort_date noprint SQL> break on sort_date skip 1 SQL> select
6 - next_day (last_day (add_months (trunc (test_date), -1)),
7 to_char (to_date ('20030101', 'YYYYMMDD'), 'DY')
8 )
9 ),
10 -1, next_day (trunc (test_date), to_char (to_date ('20030101', 'YYYYMMDD'), 'DY')),
11 next_day (last_day (trunc (test_date)),
12 to_char (to_date ('20030101', 'YYYYMMDD'), 'DY')
13 )
14 )
TEST_DATE FOLLOWING_FIRST_WED_
-------------------- -------------------- 2003/07/01 MARDI 2003/07/02 MERCREDI 2003/07/02 MERCREDI 2003/08/06 MERCREDI 2003/07/03 JEUDI 2003/08/06 MERCREDI 2003/07/04 VENDREDI 2003/08/06 MERCREDI 2003/07/05 SAMEDI 2003/08/06 MERCREDI 2003/07/06 DIMANCHE 2003/08/06 MERCREDI 2003/07/07 LUNDI 2003/08/06 MERCREDI 2003/07/08 MARDI 2003/08/06 MERCREDI 2003/08/01 VENDREDI 2003/08/06 MERCREDI 2003/08/02 SAMEDI 2003/08/06 MERCREDI 2003/08/03 DIMANCHE 2003/08/06 MERCREDI 2003/08/04 LUNDI 2003/08/06 MERCREDI 2003/08/05 MARDI 2003/08/06 MERCREDI 2003/08/06 MERCREDI 2003/09/03 MERCREDI 2003/08/07 JEUDI 2003/09/03 MERCREDI2003/08/08 VENDREDI 2003/09/03 MERCREDI
2003/10/01 MERCREDI 2003/11/05 MERCREDI 2003/10/02 JEUDI 2003/11/05 MERCREDI 2003/10/03 VENDREDI 2003/11/05 MERCREDI 2003/10/04 SAMEDI 2003/11/05 MERCREDI 2003/10/05 DIMANCHE 2003/11/05 MERCREDI 2003/10/06 LUNDI 2003/11/05 MERCREDI 2003/10/07 MARDI 2003/11/05 MERCREDI 2003/10/08 MERCREDI 2003/11/05 MERCREDIReceived on Tue Jul 22 2003 - 18:29:12 CDT
![]() |
![]() |