简体   繁体   English

在Oracle中将varchar列转换为date列

[英]Converting varchar column to date column in Oracle

I need to change column type from VARCHAR2 to DATE. 我需要将列类型从VARCHAR2更改为DATE。 The column is already storing dates in correct format. 该列已经以正确的格式存储日期。 So I was trying to do something like this 所以我试图做这样的事情

alter INM_INCIDENT rename column INM_I_REACTION_TIME to INM_I_REACTION_TIME_OLD;
alter table INM_INCIDENT add INM_I_REACTION_TIME date;
update INM_INCIDENT set INM_I_REACTION_TIME = to_date(INM_I_REACTION_TIME_OLD);
alter table INM_INCIDENT drop column INM_I_REACTION_TIME_OLD;

But I've got error on the line with update statement, so my question is, is there any nice solution for copying varchar to date like this? 但是我在使用update语句时遇到了错误,所以我的问题是,有没有很好的解决方案可以像这样将varchar复制到最新的日期?

Update: 更新:

update INM_INCIDENT set INM_I_REACTION_TIME = to_date(INM_I_REACTION_TIME_OLD, 'YYYY-MM-DD HH24:MI:SS');

You have to adjust the string YYYY-MM-DD HH24:MI:SS to your date format in your string date column. 您必须在字符串日期列中将字符串YYYY-MM-DD HH24:MI:SS为日期格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM