updating timestamp column with timestamp containing 'T'

后端 未结 2 1375
死守一世寂寞
死守一世寂寞 2021-01-26 12:19

I have timestamp column:

MAX_LOAD_DATE_TS  TIMESTAMP(6)

My load_dates comes formatted with T in between date and

相关标签:
2条回答
  • 2021-01-26 12:30

    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;
    

    Related question

    0 讨论(0)
  • 2021-01-26 12:53

    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.

    0 讨论(0)
提交回复
热议问题