Given a string representation of a day of the week (i.e. Monday, Mardi, الثلاثاء etc.) and a NLS_DATE_LANGUAGE is there any way of validating that this Day of the Week is valid?
Why is this difficult you ask? Well, if this were just English the obvious thing to do would be something like the following:
if <day_variable> in ('Monday','Tuesday', ...) then
...
I'm trying to do this, extensibly, for several countries and as I don't know (and can't be bothered) to write out all the days of the week for all current and future NLS_DATE_LANGUAGE's this isn't really an option.
Next option is an explicit TO_DATE()
, which works beautifully with Friday - I suspect that this is a coincidence 'cause it's May, but fails miserably with the rest of the week:
SQL> select to_date('Friday', 'Day') as d from dual;
D
----------
2015-05-01
SQL> select to_date('Monday', 'Day') as d from dual;
select to_date('Monday', 'Day') as d from dual
*
ERROR at line 1:
ORA-01835: day of week conflicts with Julian date
That's an interesting error... Oracle recommends to:
Remove the day of the week value from the date specification or enter the correct day of the week for the Julian date.
Removing the day of the week isn't really an option as that's all I'm interested and I don't have an incorrect day of the week for my Julian date because I don't have a Julian date.
Workaround's suggested elsewhere confirm and using alternative date formats (Dy
, dy
, FMDy
, etc.) fairly obviously results in the same error.
It appears as though Oracle represents all dates internally as Julian dates and is getting confused in this situation.
How can I validate that a named day is correct in Oracle?