简体   繁体   English

如何在Oracle中将日期字符串转换为日期

[英]How to convert date string to date in oracle

Screenshot of query executed The date string in ' Sat Oct 29 10:47:50 CDT 2016 ' has to be converted to date/timestamp format in oracle query. 已执行查询的屏幕快照在Oracle查询中,必须将“ Sat Oct 29 10:47:50 CDT 2016 ”中的日期字符串转换为日期/时间戳格式。 I need to extract only date and time from it. 我只需要从中提取日期和时间。 I tried using to to_date() but didn't work. 我尝试使用to_date()但没有用。 Can one someone please help. 有人可以帮忙吗?

Error: ORA-01841: (full) year must be between -4713 and +9999, and not be 0 01841. 00000 - "(full) year must be between -4713 and +9999, and not be 0" *Cause: Illegal year entered *Action: Input year in the specified range 错误:ORA-01841 :(完整)年份必须在-4713和+9999之间,并且不能为001841。00000-“(完整)年份必须在-4713和+9999之间,并且不能为0” *原因:非法输入的年份*操作:在指定范围内输入年份

Try this one: 试试这个:

SELECT TO_DATE(
   REGEXP_REPLACE('Sat Oct 29 10:47:50 CDT 2016', '^\w+ (\w+ \d+ \d{2}:\d{2}:\d{2}).+(\d{4})', '\1 \2'), 
      'Mon DD HH24:MI:SS YYYY')
FROM DUAL

Data type DATE or TIMESTAMP does not support any time zone information, you have to remove this part before you can do the conversion. 数据类型DATETIMESTAMP不支持任何时区信息,必须先删除此部分,然后才能进行转换。

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

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