我想将以下字符串转换为日期:
2004-09-30 23:53:48,140000000
我试过:
to_date('#', 'YYYY-MM-DD HH24:MI:SS,FF9')
但是PL/SQL不断抛出这个错误:
ORA-01821: date format not recognized.
FF9 对 Oracle 不正确,有什么建议吗?
Oracle
仅在字段中存储不超过秒的分数DATE
。
改用TIMESTAMP
:
SELECT TO_TIMESTAMP('2004-09-30 23:53:48,140000000', 'YYYY-MM-DD HH24:MI:SS,FF9')
FROM dual
,可能将其转换为DATE
then:
SELECT CAST(TO_TIMESTAMP('2004-09-30 23:53:48,140000000', 'YYYY-MM-DD HH24:MI:SS,FF9') AS DATE)
FROM dual
我认为您不能在 to_date 或 Oracle 中的 DATE 类型中使用小数秒。我认为您需要返回 TIMESTAMP 类型的 to_timestamp 。
为了不打开一个新话题,我将在这里添加我的“问题”——我希望这没问题。
我想在 Startdate 列中添加“XXX”列,以便获得以毫秒为单位的日期时间值。
SELECT InnerAgCallTraceEx.AgentID, InnerAgCallTraceEx.StartDate
,NUMTODSINTERVAL( (1000*sumHandle)/1000 , 'SECOND' ) as xxx
,InnerAgCallTraceEx.StartDate +NUMTODSINTERVAL( (1000*sumHandle)/1000 , 'SECOND' ) as CallEndDate,sumHandle
FROM
(
SELECT AgentID,StartDate
,to_char(cast((to_date(StartDate) )AS TIMESTAMP ( 6 )) , 'dd.mm.rrrr hh24:mi:ss.ff')as StartDate
, nvl(agRingTimeRecv,0) + nvl(clientRingTime,0) + nvl(AgTalkTimeRecv,0)
+ nvl(ClientTalkTime,0) + nvl(ClientHoldTime,0) + nvl(ClericalTime,0) AS sumHandle
FROM AgentCallTrace
WHERE AgentID=5411 AND TransferType<>-2 AND
StartDate >to_date('2022-02-22') + interval '-1' day AND
StartDate <= '2022-02-23' AND
to_date(Startdate)+(nvl(agRingTimeRecv,0) + nvl(clientRingTime,0) + nvl(AgTalkTimeRecv,0)+ nvl(ClientTalkTime,0) + nvl(ClientHoldTime,0) + nvl(ClericalTime,0))/24/60/60 >= '2022-02-22'
) InnerAgCallTraceEx