ORACLE中05-DEC-15的日期时间格式03.48.57.061000000 PM

时间:2015-11-30 11:44:40

标签: sql oracle oracle10g oracle-sqldeveloper

我在其中一张表中有时间戳(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.

2 个答案:

答案 0 :(得分:3)

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

小数秒由FF代替SSSSS

然后您应该使用年份中的任意四位数字或使用RR代替YY

你应该使用x作为" Local radix character"而不是硬编码点。

这个有效:

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

答案 1 :(得分:1)

请注意" 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