05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 12 ■ DATATYPES 535<br />

Since there is a three-hour time difference between those two time zones, even though<br />

they show the “same time” of 17:02:32.212, the interval reported is a three-hour difference.<br />

When performing TIMESTAMP arithmetic on TIMESTAMPS WITH TIME ZONE types, <strong>Oracle</strong> automatically<br />

converts both types to UTC time first <strong>and</strong> then performs the operation.<br />

TIMESTAMP WITH LOCAL TIME ZONE Type<br />

This type works much like the TIMESTAMP type. It is a 7- or 11-byte field (depending on the precision<br />

of the TIMESTAMP), but it is normalized to be stored in database’s time zone. To see this,<br />

we’ll use the DUMP comm<strong>and</strong> once again. First, we create a table with three columns—a DATE, a<br />

TIMESTAMP WITH TIME ZONE, <strong>and</strong> a TIMESTAMP WITH LOCAL TIME ZONE—<strong>and</strong> then we insert the<br />

same value into all three columns:<br />

ops$tkyte@ORA10G> create table t<br />

2 ( dt date,<br />

3 ts1 timestamp with time zone,<br />

4 ts2 timestamp with local time zone<br />

5 )<br />

6 /<br />

Table created.<br />

ops$tkyte@ORA10G> insert into t (dt, ts1, ts2)<br />

2 values ( timestamp'2005-06-05 17:02:32.212 US/Pacific',<br />

3 timestamp'2005-06-05 17:02:32.212 US/Pacific',<br />

4 timestamp'2005-06-05 17:02:32.212 US/Pacific' );<br />

1 row created.<br />

ops$tkyte@ORA10G> select dbtimezone from dual;<br />

DBTIMEZONE<br />

----------<br />

US/Eastern<br />

Now, when we dump those values as follows:<br />

ops$tkyte@ORA10G> select dump(dt), dump(ts1), dump(ts2) from t;<br />

DUMP(DT)<br />

------------------------------------<br />

DUMP(TS1)<br />

------------------------------------<br />

DUMP(TS2)<br />

------------------------------------<br />

Typ=12 Len=7: 120,105,6,5,18,3,33<br />

Typ=181 Len=13: 120,105,6,6,1,3,33,12,162,221,0,137,156<br />

Typ=231 Len=11: 120,105,6,5,21,3,33,12,162,221,0

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!