Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Conexión con bases de datos (https://www.clubdelphi.com/foros/forumdisplay.php?f=2)
-   -   error numeric overflow con applyupdates (https://www.clubdelphi.com/foros/showthread.php?t=62287)

nugame 15-12-2008 12:51:59

error numeric overflow con applyupdates
 
Hola:

Utilizo applyupdates en un programa de facturas.
Todo bien hasta que en la línea de factura pongo una cantidad de 300000 y al aplicar al applyupdates me da el siguiente error..:

Dynamic SQL error SQL error code= -303
arithmetic exception , numeric overflow , or string truncation

Solo me pasa al llegar a esas cantidades. Si no utilizo el applyupdates todo bien.

¿Hay un límite de memoria o algo?

Gracias

nugame 15-12-2008 13:02:21

Error solucionado..
 
Perdonar pero el error no está en el applyupdates está en que usé un campo decimal(9,4) y produce el overflow...

Un saludo

xEsk 15-12-2008 15:24:01

Hace no mucho, esto me paso pero con enteros, yo enviaba un Int64, y en la BD el formato era Int32, y me generaba este mismo error... La solución era evidente, cambiar a Int64 el campo de la BD.

Información sobre el error.

Cita:

2. Arithmetic overflow

If you use fixed precision datatypes (smallint, integer, bigint, decimal and numeric), it is possible that the result of calculation doesn't fit the datatype. Try casting the values in complex expressions as double precision and see whether the error goes away. If it works and you don't care about being too precise, you can leave it at that. Otherwise you need to check every operation and calculate the result.

Here's an example: if you multiply 9.12 with 8.11 (both numeric(18,2)) you would get 73.9632. If Firebird would store that into numeric(18,2) datatype, we would lose 0.0032. Doesn't look much, but when you have complex calculations, you can easily loose thousands (dollars or euros). Therefore, the result is stored in numeric(18,4).

Problems are rarely seen with such low precision as 2. Let's use some bigger precision. For example, numeric(18,6) times numeric(18,6) yields numeric(18,12) result, meaning that maximal value it can store is 9223372.036854775807. If (for example) you wish to keep only 6 digits of precision, you could use something like:

cast(value1 as numeric(18,3)) * cast(value2 as numeric(18,3))

which would yield numeric(18,6) result, but it is quite possible that you would get more accurate result by casting to double:

cast(cast(value1 as double precision) * cast(value2 as double precision) as numeric(18,6))


Also, if you have mixed multiplications and divisions it helps to change the order of operations, so that the overflow doesn't happen.
Saludos.

nugame 15-12-2008 21:15:22

Sobre el overflow..
 
Hola:

Lo que me pasó es que hace tiempo que programé esta aplicación y no se me ocurrió mejor forma que poner el campo como un DECIMAL(9,4).
Con un float seria mejor, o se cambio a un DECIMAL(10,4) se me queda resuelto.

Gracias por tu hilo..

Un saludo


La franja horaria es GMT +2. Ahora son las 23:00:04.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi