0
I need to convert a varchar
for date
so that you can filter all dates longer than a certain date, for example:
I want all dates that are larger than November 2018 to be listed, I am doing as follows:
DATA_FINAL > TO_DATE('10/11/2018', 'MM/DD/YYYY')
But I am always returned the error:
ORA-01843: not a Valid Month
What should I do? I thank you in advance.
Result of SUBSTR
:
1 09
2 08
3 04
4 26
5 28
6 07
7 17
8 13
9 11
10 12
11 01
12 18
13 21
14 16
15 31
16 20
17 22
18 29
19 19
20 25
21 02
22 05
23 03
24 10
25 15
26 14
27 27
28 06
29 24
30 30
31 23
Run:
select TO_DATE('10/11/2018', 'MM/DD/YYYY') from dual
also occurs the error? If it does not occur (as it did not happen with me) the fieldDATA_FINAL
is filled in any record with invalid date.– Melissa
I made this select here and it worked smoothly. Is there anything saved in that DATA_FINAL field that is causing the error.
– Reginaldo Rigo
select TO_DATE('10/11/2018', 'MM/DD/YYYY') from dual works, but in select da the error I mentioned, and so I saw no date with wrong format.
– Stand Alone
Select only a few lines. I think it will work. Until you select the line that DATA_FINAL is invalid.
– Reginaldo Rigo
If your dates are in American format your to_date is 100% correct! A possible test would be to replace to_date with a Sysdate just to check if the error persists, eliminating the date formatting and etc. Another detail, the Data_final field is of the correct date type?
– Confundir
My date is in pt-br format but of the 2 forms happens the error
– Stand Alone
Confuse, the field DATA_FINAL is of type VARCHAR, I am converting to date
– Stand Alone
DATA_FINAL > Sysdate Error message tb
– Stand Alone
Select this and post the result: select distinct substr( data_final, 1, 2 ) from your table
– Reginaldo Rigo
Reginaldo Rigo, I posted the result on top.
– Stand Alone
From what I understand the first column is the row and the second the result of the substr. Right? If that’s right. all numbers above 12 are invalid because you are trying to convert them to month. Hence the message: NOT A VALID MONTH.
– Reginaldo Rigo
Reginaldo Rigo, but I switched from mm/dd/yyyy to dd/mm/yyyy
– Stand Alone
If it still went wrong, it’s because you’re still an invalid. Check if the content of select distinct substr( data_final, 3 ,2 ) comes something other than 1 to 12
– Reginaldo Rigo
@Standalone, but in this way you are comparing a string with a date, the correct one would be to convert the varchar field to date as well. If it is not too laborious, it is advisable you convert this column to date type, record date in string format is open a port to a thousand different problems ...
– Confundir