The ORACLE SQL manual (Page 2-58 of the main 11.1 SQL Manual) states:
The total length of a datetime format model cannot exceed 22 characters.
However, I've been able to use a format string for TO_CHAR with many more characters, almost all of which are text "literals".
Is this safe (ORACLE 11)? (Perhaps the limit does not include non-date literals?)
For example:
SELECT TO_CHAR(sysdate,
'"SOMESTRING_"YYYYMMDD"_SOME LOTS MORE STRINGS OF A FILENAME PREFIX"')
FROM DUAL;
Result:
SOMESTRING_20200226_SOME LOTS MORE STRINGS OF A FILENAME PREFIX
It also works with dates from tables.
The reason I want to do this is to build a filename template in a database column; otherwise I will need to put the date format in a separate field.
P.S. Please tell me if this should be asked in a different community. I've never asked a question before, so I have no reputation to lose :-). Be nice.
It also works with dates from tables.
You put in gibberish and you get out gibberish (aka GIGO). As far as I'm concerned what you've done should throw an error - but hey, that's Oracle's problem!otherwise I will need to put the date format in a separate field.
IF it's a date, then it belongs in a date column - otherwise you'll spend a lot of time parsing strings - which is NOT what SQL was designed for! p.s. welcome to the forum! :-)