Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Precision is too small 3

Status
Not open for further replies.

gatetec

MIS
Mar 22, 2007
420
US
Can you pls shed a light on this?

The column with NUMBER (5,2) specification returns the error, "Precision is too small" when the value i.e 12345.6789

I thought it will store 12345.67.

Why does it return the error?

thx much
 
I think you answered your own question. If you setup a column with NUMBER(5,2) and trying to insert 12345.6789, it will break.

NUMBER(5,2) says 5 number before the decimal and 2 numbers after. You are giving 4 numbers after the decimal, which is great than 2. So you would need to change the column to NUMBER(5,4)
 
Hold on..."NUMBER(5,2)" means: "restrict values to 5 total digits with two of the digits behind the presumed decimal point":
Code:
create table precision (x number(5,2));

Table created.

insert into precision values (12345.67)
                              *
ERROR at line 1:
ORA-01438: value larger than specified precision allows for this column


SQL> insert into precision values (1234.56);
insert into precision values (1234.56)
                              *
ERROR at line 1:
ORA-01438: value larger than specified precision allows for this column


SQL> insert into precision values (123.45);

1 row created.
I just wanted to ensure that no one received the wrong impression from reading this thread.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm. The cost will be your freedoms and your liberty.”
 
Your problem isn't the number of digits to the right of the decimal place, but the fact that your number is too large to be stored in a number(5,2) column. (5,2) means five digits total precision with two of the five digits used for the fraction. Therefore, the largest number you can store in this column is 999.99. Here is an example of inserting a number with the correct number of decimal places that fails because the number itself is greater than 999.99.

Code:
SQL> create table test_precision (asdf number(5,2));

Table created.

SQL> insert into test_precision values (1234.56);
insert into test_precision values (1234.56)
                                   *
ERROR at line 1:
ORA-01438: value larger than specified precision allowed for this column

On the other hand, if you had a small enough number, you could get away with specifying too many decimal places. Oracle would just round off. For example

Code:
SQL> insert into test_precision values (234.567);

1 row created.

SQL> select * from test_precision;

      ASDF
----------
    234.57

So you need to redefine the column to be number(7,2) or larger in order to store the value 12345.6789.
 
Karl and I are simply Brothers from Other Mothers. <grin>

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm. The cost will be your freedoms and your liberty.”
 
...Actually, now that I think about it, we are twin brothers born, apparently, 5 minutes apart. <another grin>

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm. The cost will be your freedoms and your liberty.”
 
You are totally right SantaMufasa... I was thinking of writing NUMBER(7,2) with saying 5 number before decimal and 2 numbers after... but for some reason I wrote NUMBER(5,2). Sorry for the confusion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top