Question

I have a string column that contains the below data as an example

10/20/2005 15:08:00 
11252011 15:22:40   

I have created a temp date column that I will copy the contents into, drop the string column and rename the temp column to what the string one was.

However in my attempt to copy the data across to the new temp column I am getting the error:

ERROR
ORA-01861: literal does not match format string

Here is the SQL:

update mytable set MYDATE_TEMP = to_date(mystringcol, 'yyyy/mm/dd hh24:mi:ss')

Is there a way to copy the data across?

Was it helpful?

Solution

If those are the only 2 formats you need to handle try:

update mytable set MYDATE_TEMP = to_date(replace(mystringcol,'/',''),
                                         'mmddyyyy hh24:mi:ss')

OTHER TIPS

For the first one you could use:

update mytable set MYDATE_TEMP = to_date(mystringcol, 'mm/dd/yyyy hh24:mi:ss');

For the second one:

update mytable set MYDATE_TEMP = to_date(mystringcol, 'mmddyyyy hh24:mi:ss');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top