简体   繁体   中英

Oracle Date formatting 9999-06-15T00:00:00.000+0000 in 12c

I have got a date coming from the webservice in 9999-06-15T00:00:00.000+0000 format. How do i save this into the date column of a table in Oracle 12c DB.

I have tried

 select to_date('9999-06-15T00:00:00.000+0000', 'YYYY-MM-DDTHH24:MI:SS.fff+0000')
 from dual;

but i get an error "ORA-01821:date format not recognized"

Any help is much appreciated

The literal's format comforms to timestamp data type instead of date data type. So, using to_timestamp conversion would suffice if it had a format without the trailing portion starting from plus sign as

SELECT TO_TIMESTAMP('9999-06-15T00:00:00.000', 'YYYY-MM-DD"T"HH24:MI:SS.FF3') AS ts      
  FROM dual;

quoting letter T as "T" , and suffixing with .FF3 instead of fff as in your original format mask. Having that trailing part we need a conversion WITH TIME ZONE ( TO_TIMESTAMP_TZ ) which has TZH ( Time Zone Hour ) and TZM ( Time Zone Minute ) portions after plus sign. So, use

SELECT TO_TIMESTAMP_TZ('9999-06-15T00:00:00.000+0000', 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') AS ts
  FROM dual;

conforming to your data model.

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM