在 Oracle 中将 varchar 列转换为日期列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9618011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Converting varchar column to date column in Oracle
提问by Petr Mensik
I need to change column type from VARCHAR2 to DATE. The column is already storing dates in correct format. So I was trying to do something like this
我需要将列类型从 VARCHAR2 更改为 DATE。该列已经以正确的格式存储日期。所以我试图做这样的事情
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?
但是我在更新语句中遇到了错误,所以我的问题是,有没有像这样将 varchar 复制到日期的好的解决方案?
回答by juergen d
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
在字符串日期列中将字符串调整为您的日期格式。