【问题标题】:DateTime format for 05-DEC-15 03.48.57.061000000 PM in ORACLEORACLE 中 05-DEC-15 03.48.57.061000000 PM 的日期时间格式
【发布时间】:2016-03-04 01:04:54
【问题描述】:

我的一张桌子上有时间戳 (05-DEC-15 03.48.57.061000000 PM)。我想比较这个时间戳来检索数据。我写了以下查询

select * from ACTIVATIONRECORDS
WHERE ACTIVATIONDATE =
            TO_DATE('04-12-15 03.48.57.052000000 PM','DD-MM-YY HH.MI.SS.SSSSS PM');

但它因以下错误而失败

ORA-01861: literal does not match format string
01861. 00000 -  "literal does not match format string"
*Cause:    Literals in the input must be the same length as literals in
           the format string (with the exception of leading whitespace).  If the
           "FX" modifier has been toggled on, the literal must match exactly,
           with no extra whitespace.
*Action:   Correct the format string to match the literal.

【问题讨论】:

标签: sql oracle oracle10g oracle-sqldeveloper


【解决方案1】:

数据类型DATE 不提供任何小数秒,因此该格式不起作用。请改用TIMESTAMP

小数秒由FF 表示,而不是SSSSS

那么您应该使用四位数的年份或使用RR 而不是YY

您应该使用x 来表示“本地基数字符”,而不是硬编码的点。

这个有效:

TO_TIMESTAMP('04-12-15 03.48.57.052000000 PM','DD-MM-RR HH.MI.SSxFF PM')

【讨论】:

    【解决方案2】:

    请注意“SSSSS”表示午夜过后的秒数 (0-86399)。

     CAST(TO_TIMESTAMP('05-DEC-15 03.48.57.061000000 PM', 'YYYY-MM-DD HH:MI:SS.FF9 AM') AS DATE)
    

    http://www.techonthenet.com/oracle/functions/to_date.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-17
      • 2022-07-18
      • 2010-10-04
      • 2021-10-30
      • 1970-01-01
      相关资源
      最近更新 更多