[英]How to convert a VARCHAR to a date in ORACLE SQL?
I have that field in my table:我的表中有该字段:
2020-01-16T10:55:16..296518000
How to convert this Varchar into a date in format 'YYYY-MM-DD' ?如何将此 Varchar 转换为格式为 'YYYY-MM-DD' 的日期?
I tried:我试过:
select TRUNC(to_date(DATE_UPDATED ,'YYYY-MM-DD hh24:mi:ss')) from JOB_SCHEDULE_TBL
but I'm getting an error:但我收到一个错误:
ORA-01830: date format picture ends before converting entire input string
Just use substr()
:只需使用substr()
:
select to_date(SUBSTR(DATE_UPDATED, 1, 10) ,'YYYY-MM-DD')
The trunc()
is unnecessary. trunc()
是不必要的。
You are confusing the format of DATE
with what you are seeing on the screen.您将DATE
的格式与您在屏幕上看到的内容混淆了。 A DATE
data type has no "format". DATE
数据类型没有“格式”。 It's Oracle's internal, binary format.这是 Oracle 的内部二进制格式。 Even when you SELECT TO_DATE
..., the result is going to get displayed by the client, and to do so the client will have to peform (under the covers) a TO_CHAR
on the resulting DATE
.即使您SELECT TO_DATE
...,结果也会由客户端显示,为此,客户端必须在结果DATE
上执行(在TO_CHAR
) TO_CHAR
。 And that implied to_char will use the current system/session/ settings for TNS_DATE_FORMAT
.这暗示 to_char 将使用TNS_DATE_FORMAT
的当前系统/会话/设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.