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.

540<br />

CHAPTER 12 ■ DATATYPES<br />

ops$tkyte@ORA10G> select to_dsinterval( '10 02:03:02.3312' )<br />

2 from dual;<br />

TO_DSINTERVAL('1002:03:02.3312')<br />

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

+000000010 02:03:02.331200000<br />

or just use an INTERVAL literal in SQL itself:<br />

ops$tkyte@ORA10G> select interval '10 02:03:02.3312' day to second<br />

2 from dual;<br />

INTERVAL'1002:03:02.3312'DAYTOSECOND<br />

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

+10 02:03:02.331200<br />

LOB Types<br />

LOBs, or large objects, are the source of much confusion, in my experience. They are a misunderstood<br />

datatype, both in terms of how they are implemented <strong>and</strong> how best to use them. This<br />

section provides an overview of how LOBs are stored physically <strong>and</strong> the considerations you<br />

must take into account when using a LOB type. They have many optional settings, <strong>and</strong> getting<br />

the right mix for your application is crucial.<br />

There are four types of LOBs supported in <strong>Oracle</strong>:<br />

• CLOB: A character LOB. This type is used to store large amounts of textual information,<br />

such as XML or just plain text. This datatype is subject to character set translation—that<br />

is, the characters in this field will be converted from the database’s character set to the<br />

client’s character set upon retrieval, <strong>and</strong> from the client’s character set to the database’s<br />

character set upon modification.<br />

• NCLOB: Another type of character LOB. The character set of the data stored in this column<br />

is the national character set of the database, not the default character set of the<br />

database.<br />

• BLOB: A binary LOB. This type is used to stored large amounts of binary information,<br />

such as word documents, images, <strong>and</strong> anything else you can imagine. It is not subject<br />

to character set translation. Whatever bits <strong>and</strong> bytes the application writes into a BLOB<br />

are what are returned by the BLOB.<br />

• BFILE: A binary file LOB. This is more of a pointer than a database-stored entity. The<br />

only thing stored in the database with a BFILE is a pointer to a file in the operating system.<br />

The file is maintained outside of the database <strong>and</strong> is not really part of the database<br />

at all. A BFILE provides read-only access to the contents of the file.<br />

When discussing LOBs, I’ll break the preceding list into two pieces: LOBs stored in the<br />

database, or internal LOBs, which include CLOB, BLOB, <strong>and</strong> NCLOB; <strong>and</strong> LOBs stored outside of<br />

the database, or the BFILE type. I will not discuss CLOB, BLOB, or NCLOB independently, since<br />

from a storage <strong>and</strong> option perspective they are the same. It is just that a CLOB <strong>and</strong> NCLOB

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

Saved successfully!

Ooh no, something went wrong!