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.

510<br />

CHAPTER 12 ■ DATATYPES<br />

999999 1000000 4 2<br />

99999999 100000000 5 2<br />

9999999999 10000000000 6 2<br />

999999999999 1000000000000 7 2<br />

99999999999999 100000000000000 8 2<br />

9999999999999999 10000000000000000 9 2<br />

999999999999999999 1000000000000000000 10 2<br />

99999999999999999999 100000000000000000000 11 2<br />

9999999999999999999999 10000000000000000000000 12 2<br />

999999999999999999999999 1000000000000000000000000 13 2<br />

99999999999999999999999999 100000000000000000000000000 14 2<br />

9999999999999999999999999999 10000000000000000000000000000 15 2<br />

14 rows selected.<br />

We can see that as we added significant digits to X, the amount of storage required took<br />

increasingly more room. Every two significant digits added another byte of storage. But a<br />

number just one larger consistently took 2 bytes. When <strong>Oracle</strong> stores a number, it does so by<br />

storing as little as it can to represent that number. It does this by storing the significant digits,<br />

an exponent used to place the decimal place, <strong>and</strong> information regarding the sign of the number<br />

(positive or negative). So, the more significant digits a number contains, the more storage<br />

it consumes.<br />

That last fact explains why it is useful to know that numbers are stored in varying width<br />

fields. When attempting to size a table (e.g., to figure out how much storage 1,000,000 rows<br />

would need in a table), you have to consider the NUMBER fields carefully. Will your numbers take<br />

2 bytes or 20 bytes? What is the average size? This makes accurately sizing a table without representative<br />

test data very hard. You can get the worst-case size <strong>and</strong> the best-case size, but the<br />

real size will likely be some value in between.<br />

BINARY_FLOAT/BINARY_DOUBLE Type Syntax <strong>and</strong> Usage<br />

<strong>Oracle</strong> 10g introduced two new numeric types for storing data; they are not available in any<br />

release of <strong>Oracle</strong> prior to version 10g. These are the IEEE st<strong>and</strong>ard floating-points many programmers<br />

are used to working with. For a full description of what these number types look<br />

like <strong>and</strong> how they are implemented, I suggest reading http://en.wikipedia.org/wiki/<br />

Floating-point. It is interesting to note the following in the basic definition of a floatingpoint<br />

number in that reference (emphasis mine):<br />

A floating-point number is a digital representation for a number in a certain subset of<br />

the rational numbers, <strong>and</strong> is often used to approximate an arbitrary real number on a<br />

computer. In particular, it represents an integer or fixed-point number (the signific<strong>and</strong><br />

or, informally, the mantissa) multiplied by a base (usually 2 in computers) to some integer<br />

power (the exponent). When the base is 2, it is the binary analogue of scientific<br />

notation (in base 10).

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

Saved successfully!

Ooh no, something went wrong!