05.11.2015 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 12 ■ DATATYPES 511<br />

They are used to approximate numbers; they are not nearly as precise as the built-in<br />

<strong>Oracle</strong> NUMBER type described previously. Floating-point numbers are commonly used in<br />

scientific applications <strong>and</strong> are useful in many types of applications due to the fact that they<br />

allow arithmetic to be done in hardware (on the CPU, the chip) rather than in <strong>Oracle</strong> subroutines.<br />

Therefore, the arithmetic is much faster if you are doing real number-crunching in a<br />

scientific application, but you would not want to use floating-points to store financial<br />

information.<br />

The syntax for declaring columns of this type in a table is very straightforward:<br />

BINARY_FLOAT<br />

BINARY_DOUBLE<br />

That is it. There are no options to these types whatsoever.<br />

Non-Native Number Types<br />

In addition to the NUMBER, BINARY_FLOAT, <strong>and</strong> BINARY_DOUBLE types, <strong>Oracle</strong> syntactically supports<br />

the following numeric datatypes:<br />

■Note When I say “syntactically supports,” I mean that a CREATE statement may use these datatypes,<br />

but under the covers they are all really the NUMBER type. There are precisely three native numeric formats<br />

in <strong>Oracle</strong> 10g Release 1 <strong>and</strong> later <strong>and</strong> only one native numeric format in <strong>Oracle</strong>9i Release 2 <strong>and</strong> earlier.<br />

The use of any other numeric datatype was always mapped to the native <strong>Oracle</strong> NUMBER type.<br />

• NUMERIC(p,s): Maps exactly to a NUMBER(p,s). If p is not specified, it defaults to 38.<br />

• DECIMAL(p,s) or DEC(p,s): Maps exactly to a NUMBER(p,s). If p is not specified, it defaults<br />

to 38.<br />

• INTEGER or INT: Maps exactly to the NUMBER(38) type.<br />

• SMALLINT: Maps exactly to the NUMBER(38) type.<br />

• FLOAT(b): Maps to the NUMBER type.<br />

• DOUBLE PRECISION: Maps to the NUMBER type.<br />

• REAL: Maps to the NUMBER type.<br />

Performance Considerations<br />

In general, the <strong>Oracle</strong> NUMBER type is the best overall choice for most applications. However,<br />

there are performance implications associated with that type. The <strong>Oracle</strong> NUMBER type is a<br />

software datatype—it is implemented in the <strong>Oracle</strong> software itself. We cannot use native hardware<br />

operations to add two NUMBER types together, as it is emulated in the software. The<br />

floating-point types, however, do not have this implementation. When we add two floatingpoint<br />

numbers together, <strong>Oracle</strong> will use the hardware to perform the operation.

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

Saved successfully!

Ooh no, something went wrong!