Oracle dates do not have time zone information. Instead, you need to use the TIMESTAMP data type.
It works something like this:
SQL> desc tz Name Null? Type ----------------------------------------- -------- ---------------------------- ID NUMBER TS TIMESTAMP(6) WITH TIME ZONE TNOW TIMESTAMP(6) WITH TIME ZONE SQL> insert into tz 2 values (1 3 , to_timestamp_tz('2002-10-10 12:00:00-05:00' 4 , 'YYYY-MM-DD HH24:MI:SSTZH:TZM') 5 , systimestamp) 6 / 1 row created. SQL> select * from tz 2 / ID ---------- TS --------------------------------------------------------------------------- TNOW --------------------------------------------------------------------------- 1 10-OCT-02 12.00.00.000000 -05:00 23-AUG-10 17.37.06.502000 +01:00 SQL>
Note that there is a difficult problem with T in the XSD record. This throws an ORA-01858 exception because it is not a valid format in Oracle. I am sure there is a workaround, but currently it is slipping away from me.
Well, one way is to use the SUBSTR () function, which separates the two parts of the timestamp, as Bob shows. But there has to be a more elegant way.
It probably doesn't qualify as βelegantβ, but as a string, we can use the substitution function to get rid of the annoying T:
SQL> insert into tz 2 values (2 3 , to_timestamp_tz(translate('2003-10-10T12:00:00-05:00', 'T', ' ') 4 , 'YYYY-MM-DD HH24:MI:SSTZH:TZM') 5 , systimestamp) 6 / 1 row created. SQL> select * from tz 2 / ID ---------- TS --------------------------------------------------------------------------- TNOW --------------------------------------------------------------------------- 1 10-OCT-02 12.00.00.000000 -05:00 23-AUG-10 17.37.06.502000 +01:00 2 10-OCT-03 12.00.00.000000 -05:00 23-AUG-10 17.53.37.113000 +01:00 SQL>
But given all the efforts that Oracle has implemented in XMLDB, it is rather annoying that there is no finer solution.
"I do not understand how you are -05: 00."
In my original example, I use a mask of the format 'YYYY-MM-DD HH24:MI:SS-TZH:TZM' . This interprets - in the time zone as a separator, not a minus sign. Consequently, he returned +05: 00. Since then I have corrected my sample code to remove the last dash. Now the time zone is correctly displayed as -05: 00. Sorry for any confusion.