Skip to content
Advertisement

How do I fix ORA-01843: not a valid month?

So at the query level, I have it:

And I’ve tried looking at a few articles with one most notable:

How to change the date format in Oracle BI Publisher?

I have also tried using:

While going through structure and XML I noticed my date is in string format:

element name=”DATETIME” value=”DATETIME” label=”DATETIME” dataType=”xsd:string” breakOrder=”ascending” fieldOrder=”3″

So I removed the to_char to get the date format

The error I’ve been getting is:

java.sql.SQLDataException: ORA-01843: not a valid month

How do I fix this issue?

EDIT: Format for the column, TIMESTAMP, the format is CHAR(14) Example of values is like 20200701103038 It runs perfectly in SQL Developer

Advertisement

Answer

Well, it is quite a bad and extended practice to store DATES as strings, either using varchar2 or char. Anyway, having say that, I think you have a problem with your settings or the way you are constructing your query:

Besides, as you said, if your data is stored as YYYYMMDDHHMISS, you are applying the wrong date mask YYYY-MM-DD HH24:MI:SS to that char. I would use CAST to define the field as DATE.

Example

Update

If you can’t change your NLS Session settings, then you must apply a TO_CHAR to the resulting output. But in your case, you want to operate with dates, so as long as it is a date value you want to operate with, you can forget about the mask.

So, if you want to compare the date to another date, don’t use to_char. If you want to show the value in a specific format, when you have no option to change the settings, then use to_char.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement