I have timestamp column:
MAX_LOAD_DATE_TS TIMESTAMP(6)
My load_dates
comes formatted with T in between date
and time
.
2014-07-02T10:46:22
Is there a way to convert this to legit timestamp
on oracle?
You can embed literals in the format string if they're double-quoted:
select to_timestamp('2014-07-02T10:46:22', 'YYYY-MM-DD"T"HH24:MI:SS') from dual;
TO_TIMESTAMP('2014-07-02T10:46:22','YYYY-MM-DD"T"HH24:MI:SS')
-------------------------------------------------------------
02-JUL-14 10.46.22.000000000
That works with to_date()
as well as to_timestamp()
, and with to_char()
going the other way.
This is mentioned in the documentation:
Punctuation and Character Literals in Datetime Format Models
You can include these characters in a date format model:
- Punctuation such as hyphens, slashes, commas, periods, and colons
- Character literals, enclosed in double quotation marks
These characters appear in the return value in the same location as they appear in the format model.
You can use the appropriate format string as well as the CAST function, as below:
SELECT
CAST(TO_DATE('2014-07-02T10:46:22', 'YYYY-MM-DD"T"HH24:MI:SS') AS TIMESTAMP(6)) AS timestamp_value
FROM table;