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.

530<br />

CHAPTER 12 ■ DATATYPES<br />

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

2 ( dt date,<br />

3 ts timestamp(0)<br />

4 )<br />

5 /<br />

Table created.<br />

ops$tkyte@ORA10G> insert into t values ( sysdate, systimestamp );<br />

1 row created.<br />

ops$tkyte@ORA10G> select dump(dt,10) dump, dump(ts,10) dump<br />

2 from t;<br />

DUMP<br />

DUMP<br />

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

Typ=12 Len=7: 120,105,6,28,11,35,41 Typ=180 Len=7: 120,105,6,28,11,35,41<br />

The datatypes are different (the TYP=FIELD indicates that), but the manner in which they<br />

store data is identical. The TIMESTAMP datatype will differ in length from the DATE type when<br />

you specify some number of fractional seconds to preserve, for example:<br />

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

2 ( dt date,<br />

3 ts timestamp(9)<br />

4 )<br />

5 /<br />

Table created.<br />

ops$tkyte@ORA10G> insert into t values ( sysdate, systimestamp );<br />

1 row created.<br />

ops$tkyte@ORA10G> select dump(dt,10) dump, dump(ts,10) dump<br />

2 from t;<br />

DUMP<br />

DUMP<br />

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

Typ=12 Len=7: 120,105,6,28,11,46,21 Typ=180 Len=11: 120,105,6,28,11,46,21<br />

,44,101,192,208<br />

Now the TIMESTAMP consumes 11 bytes of storage, <strong>and</strong> the extra 4 bytes at the end contain<br />

the fractional seconds, which we can see by looking at the time that was stored:<br />

ops$tkyte@ORA10G> alter session set nls_date_format = 'dd-mon-yyyy hh24:mi:ss';<br />

Session altered.<br />

ops$tkyte@ORA10G> select * from t;

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

Saved successfully!

Ooh no, something went wrong!