How can I know if 10385274000 fits into: NUMBER(10) for Oracle?

OscarRyz picture OscarRyz · Aug 1, 2009 · Viewed 17.5k times · Source

I been working the whole week to troubleshot a production error.

I have eventually got the the point where I can find the culprit record which is causing all the mess.

I've got the following error message:

java.sql.SQLException: [BEA][Oracle JDBC Driver][Oracle]ORA-01438: value larger than specified precision allows for this column

Eventuall from all the info I think this might be the wrong data, the system is trying to insert:

10385274000

Into a NUMBER(10)

How can I know if that value fits or no?

Thank you

EDIT

As per Michel Todd suggestion:

create table xyz( testfield number( 10 ) );

insert into xyz values( 10385274000 )


Error: ORA-01438: value larger than specified precision allowed for this column

Thank you guys!!!

Thank you stackoverflow

EDIT

Notes to my self ( not to forget what was the problem )

I had this Oracle product which stores in a database table the time of an event

START_TIME|END_TIME

It turns out everynight it backups this information into another table but performs a trnsformation in the process. It does store as:

TOTALTIME

The problem comes when this field is calculated by subtracting ENDTIME - STARTTIME. The resulting number is stored in this column which is defined as: NUMBER(10)

Well, it turns out if END_TIME-START_TIME are too far away in the time ( about 4 months or so ) the value ( in milliseconds ) would be SO big it won't fit in the target column ( I guess it has something like endTime.getTime() - startTime.getTime() inside the code )

All this sounds too easy and too silly now, but it took me 4 day+ to find out, because since this is a closed application I didn't have a clue of what was happening, the only thing I've got was the stacktrace.

I had to reverse engineer ( in the OLD sense of the word, by hand and obviously with out the source) the entire process to find this out.

When I did it, I've got the same error in my "hand coded migrator" and find out how to solve it!

Answer

Emil H picture Emil H · Aug 1, 2009

The number 10 in NUMBER(10) specifies the field size. That means that the field can hold a number up to 10 characters long. Your number has 11 digits and thus the value is to large to fit. Anything smaller than (<) 10 billion (10 000 000 000) can be inserted without trouble. That's what you need to check for if you want to validate the value before inserting.