TheDS
TheDS

Reputation: 101

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

Upvotes: 0

Views: 1228

Answers (1)

Barbaros Özhan
Barbaros Özhan

Reputation: 65363

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

Upvotes: 1

Related Questions