What is the Oracle date formatting mask for time zones?

前端 未结 2 1458
一向
一向 2020-12-21 01:02

I need to insert a date format from an outside source which includes the three letter code for time zone, but the TZD formatting mask does not seem to work.

相关标签:
2条回答
  • 2020-12-21 01:18

    Date columns don't have timezone as an option. You'd have to create the column as data type TIMESTAMP WITH TIME ZONEorTIMESTAMP WITH LOCAL TIME ZONE, and besides, the TO_DATE function doesn't understand the TIME ZONE format mask you're applying.

    SQL> CREATE TABLE T
      2  (DT DATE,
      3   TS TIMESTAMP,
      4   TSTZ TIMESTAMP WITH TIME ZONE,
      5   TSLTZ TIMESTAMP WITH LOCAL TIME ZONE);
    
    Table created.
    
    SQL> INSERT INTO T (TSLTZ) VALUES 
      2  (to_timestamp_tz('Thu, 18 Feb 2010 08:37:00 EST','DY, DD Mon YYYY HH24:MI:SS TZD'))
      3  /
    
    1 row created.
    
    SQL> INSERT INTO T (TSTZ) VALUES 
      2  (to_timestamp_tz('Thu, 18 Feb 2010 08:37:00 EST','DY, DD Mon YYYY HH24:MI:SS TZD'))
      3  /
    
    1 row created.
    
    0 讨论(0)
  • 2020-12-21 01:25

    If timezone is not relevant for you, just strip it from the string using SUBSTR function and insert as in your second example.

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