The DAY
format mask returns a space-padded string. Assuming that your session's language is set to English, the longest day is WEDNESDAY
which is 9 characters so all the other day strings would be padded out to 9 characters as well. This made sense long ago when reports were generally printed out in fixed width fonts so having functions return strings of consistent length simplified formatting issues.
You can remove the extra spaces by adding fm
to your format mask
IF( to_char( sysdate, 'fmDAY' ) = 'TUESDAY' )
You can also use a format mask that produces the abbreviated day name which won't be space padded
IF( to_char( sysdate, 'DY' ) = 'TUE' )
Or, if you really wanted to, you could use the DAY
format mask and compare against a space-padded string
IF( to_char( sysdate, 'DAY' ) = 'TUESDAY ' )
If you are writing code that needs to deal with an environment where you need to support multiple languages, you'd need to account for the fact that weeks start on different days in different regions and the names and abbreviations of the days of the week are different in different languages. If you're in this situation, you'd need to pass in a third parameter to the to_char
function to specify your NLS settings.
IF( to_char( sysdate, 'fmDAY', 'NLS_DATE_LANGUAGE=ENGLISH' ) = 'TUESDAY' )