문제

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?

도움이 되었습니까?

해결책

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')

다른 팁

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');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top