Question

Based on Oracle document, it stores different parts of timestamp with time zone internally in terms of numbers. I read this article http://www.orafaq.com/wiki/Timestamp which explains the algorithm of internal format of timestamp. So I did a simple test to verify it.

 SQL> create table tz_test(id number, tz timestamp with time zone);

 Table created.

 SQL> insert into tz_test values(1, timestamp '1999-10-29 21:00:00 -7:00');

 1 row created.

 SQL> insert into tz_test values(2, timestamp '1999-10-29 21:00:00 US/Pacific');

 1 row created.

 SQL> select id, dump(tz, 10) from tz_test where tz=timestamp '1999-10-29 21:00:00 -7:00';

    ID     DUMP(TZ,10)
 --------------------------------------------------------------------------------

     1     Typ=181 Len=13: 119,199,10,30,5,1,1,0,0,0,0,13,60

     2     Typ=181 Len=13: 119,199,10,30,5,1,1,0,0,0,0,137,156

The article in orafaq talks about how oracle stores the time zone offset and my first row of the test proved that. But there's nothing about how to store the time zone literal. So I'm keen on knowing it. I also want to know internally how oracle evaluate timestamp '1999-10-29 21:00:00 -7:00' and timestamp '1999-10-29 21:00:00 US/Pacific' are identical.

Was it helpful?

Solution

They appear to be the region IDs from the time zone file, e.g. $ORACLE_HOME/oracore/zoneinfo/timezone_14.dat.

In this SQL Fiddle, a value with time zone region PST8PDT has the last two bytes stood as 0x83, 0x64; which matches the values suggested by MOS document ID 414590.1.

I can't see any reference that lists all the possible values, or any obvious way to examine the time zone file. It doesn't seem to be documented, which isn't unreasonable for an internal format. You could figure out values you're interested in, or all values, using the same method but I'm not sure why you'd want to.

There's another support document you might find useful, 340512.1, which is a FAQ about timestamps and time zones.

To convert a region name to an offset value you can use the tz_offs function, but it uses the current date - so the answer you get will depend on whether you ask in the winter or summer. To get the offset for a certain date you need to compare that timestamp with a UTC timestamp. And you can't really go the other way, as multiple time zone regions map the same offset.

OTHER TIPS

TIMESTAMP '1999-10-29 21:00:00 -7:00' and TIMESTAMP'1999-10-29 21:00:00 US/Pacific' are not identical.

You see the difference when you run this query for example:

SELECT 
    TIMESTAMP '1999-12-29 21:00:00 -7:00', 
    TIMESTAMP '1999-12-29 21:00:00 US/Pacific',
    TIMESTAMP '1999-06-29 21:00:00 -7:00', 
    TIMESTAMP '1999-06-29 21:00:00 US/Pacific'
FROM dual;

29.12.1999 21:00:00.000000000 -07:00    
29.12.1999 21:00:00.000000000 -08:00    
29.06.1999 21:00:00.000000000 -07:00    
29.06.1999 21:00:00.000000000 -07:00

US/Pacific considers Daylight Saving Times, -7:00 does not!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top