to-date

Date comparison returns unusual result - SQL Oracle

前提是你 提交于 2019-11-26 17:25:11
问题 I have a table of the structure: +---------+--------------+-----------------+---------------+-------+------+ | week_no | long_week_no | week_start_date | week_end_date | month | year | +---------+--------------+-----------------+---------------+-------+------+ | 1 | 1A | 01/01/2015 | 03/01/2015 | JAN | 2015 | | 1 | 1B | 04/01/2015 | 10/01/2015 | JAN | 2015 | | 2 | 2 | 11/01/2015 | 17/01/2015 | JAN | 2015 | | 3 | 3 | 18/01/2015 | 24/01/2015 | JAN | 2015 | | .. | .. | .. | .. | .. | .. | | 51 |

String to date in Oracle with milliseconds

折月煮酒 提交于 2019-11-26 13:50:38
问题 I want to convert the follow string to date: 2004-09-30 23:53:48,140000000 I tried: to_date('#', 'YYYY-MM-DD HH24:MI:SS,FF9') But PL/SQL keep throwing this error: ORA-01821: date format not recognized. FF9 is incorrect for Oracle, any suggestion? 回答1: Oracle stores only the fractions up to second in a DATE field. Use TIMESTAMP instead: SELECT TO_TIMESTAMP('2004-09-30 23:53:48,140000000', 'YYYY-MM-DD HH24:MI:SS,FF9') FROM dual , possibly casting it to a DATE then: SELECT CAST(TO_TIMESTAMP(