A table I am querying has dates stored as varchar2. I need to compare the dates stored as varchar2 with sysdate using BETWEEN sysdate-1 AND sysdate-30 (to return varchar2 dates from the last month).
When specifying TO_DATE(varchar2, 'DD-MON-YYYY') I get error "literal does not match format string".
I am stuck as Oracle documentation says this is an acceptable format for TO_DATE() when converting from varchar2.
UPDATE: This is a corporate database, I did not design the DB and can only work with what I have available. The data set is enormous and is automatically updated by SCADA devices, over 10,000 devices daily.
SELECT device_name, read_date, sysdate
FROM oracle_database
------- Data Returned by query --------
device_name read_date sysdate
Device 1 5/14/2013 22-Sep-14
Device 2 5/14/2013 22-Sep-14
Device 3 5/14/2013 22-Sep-14
Device 4 5/14/2013 22-Sep-14
Device 5 5/14/2013 22-Sep-14
Device 6 5/14/2013 22-Sep-14
Device 7 5/14/2013 22-Sep-14
Results from using TO_DATE
SELECT device_name, TO_DATE(read_date, 'DD-MON-YY'), sysdate
------- Data Returned by query ----------
ORA-01861: literal does not match format string
nls_date_formatif he is unsure about the nls settings, but I refrained since I amateurs playing more at query level format than session level, and it will override the session level settings. Let's see what OP tells us regarding further details. I will try to improvise my answer based on new inputs by OP. - Lalit Kumar B