我收到来自像我们下面的API之一的响应,甲骨文UTC日期字符串插入日期列
'createdate' => 'Sun Jan 31 04:40:15 UTC 2016'
我使用Oracle数据库来保存API的数据,我用Perl语言解析API数据。在将上面的日期字段插入到db之前,我在我的Perl中将以下字符串转换为日期,并且工作正常。
$res->{'createdate'} = strftime ('%d-%b-%y',localtime(str2time($res->{'createdate'})));
我已经尝试使用像下面的插入查询(甲骨文)相同,所以我可以删除perl转换。它结束了一些错误。请帮助我。谢谢。
对于如:
insert
into device_det (id, createdate)
values (111111,TO_TIMESTAMP('Wed Aug 16 16:59:31 UTC 2017', 'YYYY-MM-DD'));
这给了如下错误。
Error report -
SQL 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
“TO_TIMESTAMP”的第二个参数不应该是匹配该数据串的模式吗? 'YYYY-MM-DD'是你的目标,对吧?根据[文档](https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions193.htm),目标始终是“TIMESTAMP”类型。但是我从来没有用过Oracle,我只是在阅读文档。 – simbabque
尝试'TO_TIMESTAMP_TZ('Wed Aug 16 16:59:31 UTC 2017','Dy Mon DD HH24:MI:SS TZR YYYY')' –