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 513<br />

■Note If you are interested in the gory details of floating-point arithmetic <strong>and</strong> the subsequent loss of precision,<br />

see http://docs.sun.com/source/806-3568/ncg_goldberg.html.<br />

It should be noted that we can sort of have our cake <strong>and</strong> eat it too, here. Using the built-in<br />

CAST function, we can perform an on-the-fly conversion of the <strong>Oracle</strong> NUMBER type to a floatingpoint<br />

type, prior to performing the complex math on it. This results in a CPU usage that is<br />

much nearer to that of the native floating-point types:<br />

select sum(ln(cast( num_type as binary_double ) )) from t<br />

call count cpu elapsed<br />

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

total 4 0.12 0.17<br />

This implies that we may store our data very precisely, <strong>and</strong> when the need for raw speed<br />

arises, <strong>and</strong> the floating-point types significantly outperform the <strong>Oracle</strong> NUMBER type, we can<br />

use the CAST function to accomplish that goal.<br />

LONG Types<br />

LONG types come in two flavors in <strong>Oracle</strong>:<br />

• A LONG text type capable of storing 2GB of text. The text stored in the LONG type is subject<br />

to character set conversion, much like a VARCHAR2 or CHAR type.<br />

• A LONG RAW type capable of storing 2GB of raw binary data (data that is not subject to<br />

character set conversion).<br />

The LONG types date back to version 6 of <strong>Oracle</strong>, when they were limited to 64KB of data.<br />

In version 7, they were enhanced to support up to 2GB of storage, but by the time version 8<br />

was released, they were superseded by the LOB types, which we will discuss shortly.<br />

Rather than explain how to use the LONG type, I will explain why you do not want to use<br />

the LONG (or LONG RAW) type in your applications. First <strong>and</strong> foremost, the <strong>Oracle</strong> documentation<br />

is very clear in its treatment of the LONG types. The <strong>Oracle</strong> SQL Reference manual states the<br />

following:<br />

Do not create tables with LONG columns. Use LOB columns (CLOB, NCLOB, BLOB) instead.<br />

LONG columns are supported only for backward compatibility.<br />

Restrictions on LONG <strong>and</strong> LONG RAW Types<br />

The LONG <strong>and</strong> LONG RAW types are subject to the restrictions outlined in Table 12-2. Even<br />

though it might be considered jumping ahead, I’ve added a column to say whether the corresponding<br />

LOB type, which is the replacement for the LONG/LONG RAW types, is subject to the<br />

same restriction.

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

Saved successfully!

Ooh no, something went wrong!