[英]Conversion of varchar to timestamp in oracle 11g R2
I am trying to convert varchar to timestamp with below query. 我试图通过以下查询将varchar转换为时间戳。
select staging.revival_date ,
case when staging.revival_date <> 'Unknown'
then
TO_TIMESTAMP(
to_char(staging.revival_date,'dd-MON-YY')
||
'00:00', 'dd-MM-YY HH24:MI'
)
else null
end
revival_on
from stg_avg_gen_plant_outage staging
revival_date : varchar2 revival_date:varchar2
But it gives me error like : Invalid number
但它给我一个错误: Invalid number
What is going wrong? 出了什么问题?
revival_date
is a varchar (because sometimes it can apparently contain 'Unknown' so it makes no sense to use to_char()
on it. revival_date
是一个varchar(因为有时它显然可以包含'Unknown',所以在它上面使用to_char()
是没有意义的。
When you convert to timestamp the format has to match the date stored as a string. 转换为时间戳时,格式必须与存储为字符串的日期相匹配。 In your case you're trying to make something in the format 'dd-MON-YYHH24:MI' (without a space between the date and time components) and telling to_timestamp
to expect strings in the format 'dd-MM-YY HH24:MI'. 在你的情况下,你试图用'dd-MON-YYHH24:MI'格式(在日期和时间组件之间没有空格)并告诉to_timestamp
以格式'dd-MM-YY HH24: MI”。 So you need to 所以你需要
Make sure there is indeed a space between the data and time components, and 确保数据和时间组件之间确实存在空间,并且
Make the "month" component match. 使“月份”组件匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.