I am working on an assignment where I need to display the system date in a very specific way in SQL. The form is supposed to be as follows:

Day of the week with just the first letter capitalized, the month number in Roman Numerals (capitalized), the day of the month, the year spelled out in capital letters with anno domini, the day of the year from the Julian calendar with the phrase "Day of the year", number of seconds past midnight with the phrase "Seconds past midnight"

I reached up to the actual number of seconds past midnight, but I can't seem to add "Seconds past midnight" to it.

I have looked for syntax online and didn't find exactly what I needed. It's possible my search queries weren't worded correctly or that I didn't look far enough. My textbook isn't very clear to me on this, either. The only thing I've seen in there is an explanation of the difference between CURRENTDATE and SYSDATE.

This is what I have so far. I realize it may be entirely wrong. I have attempted it without the + and also without the quotes around the phrase.

    (SYSDATE, 'Dy, RM, D, YEAR AD, DDD "Day of the year", SSSSS "Seconds past midnight") "NOW"

I expected the output to say Fri, IV, 19, TWENTY NINETEEN AD, 109 Day of the year, 73829 Seconds past midnight but it's giving me the following error: ORA-01801: date format is too long for internal buffer

1 Answers

mathguy On Best Solutions

You could cheat - concatenate the last hardcoded text to the result of TO_CHAR, instead of including it in the format model.

       || ' Seconds past midnight' "NOW"

Fri, IV  , 19, TWENTY NINETEEN AD, 109 Day of the year , 54236 Seconds past midnight

Note also that the third format element must be DD (you have D, which will not give you the two-digit day of the month, in this case 19).

Further clarification on the error you got: This is written in the Oracle documentation


The total length of a datetime format model cannot exceed 22 characters.

However, a quick count shows that the length of the format model in my solution is in fact more than 22 characters. It is not uncommon for Oracle documentation to be plain wrong. In this case, there seems to be a limit to the length of a format model, even though it is not the one in the documentation...