oracle data type = number, how does exponent relate to precision and scale?
I've been trying to understand Orac开发者_开发百科le database's use of data type = number. I ran across the following link:
ask tom
and I'm having trouble interpreting it. I should mention I don't have Oracle background, but approaching this from Matlab experience. I understand number data type has a precision and scale. What I don't understand is how the exponent is treated here. Is the exponent a separate consideration from precision and scale? Or, is the exponent limited by precision and scale?
Here's my confusion -- the above link starts with:
Q: I declared the datatype of a column of a table as NUMBER & Presumed it to be Number(38) to be specific. But What I found to be strange that, it is accepting digits beyong 38 digits.ie. 1.111E+125. If the Datatype's precision is 38 and scale can range from -84 to 127 how this value can insert into the column.
A: and we said... 1.111e+125 only has 4 digits of precision (number of digits needed to represent the number -- in this case 1111).
Which seems to indicate the exponent is treated separate from precision and scale. But a few messages down someone else asks:
Q: When I create a table like: create table test(no number(7)) ; insert into test values(1.00e+25) ; it gives the following error message: ORA-01438: value larger than specified precision allows for this column. Can u pls. explain this.
A: you said 7 digits, you gave it 25
which seems to indicate the exponent is limited by the precision. Hoping someone can help me understand how both answers can be correct.
number(7)
is an integer with (at most) seven digits (in the "normal" decimal representation). Note that fractions are not allowed. Numbers larger than 9,999,999 will not be accepted. This has nothing to do with how many significant digits they have. This is a "business constraint" put in place by you.
number(7,2)
would be a number with seven digits, including two after the decimal point
number
is a floating point number with 38 digits of precision (i.e. 38 significant digits, no matter where they are in relation to the decimal point). The exponent can be anything between -84 and 125. There are no "business contraints" here. You can store as much as Oracle can store (which is 38 digits and the exponent between -84 and 125).
Note that all these numbers are stored as decimal data (to avoid rounding errors when converting into binary), so "digits" really mean decimal digits (not binary bits).
精彩评论