"Arithmetic Overflow" error getting AVG of field - how to solve?

After some research, it appears that the problem is in a precision mis-match between Oracle floats and .NET floats, and that OracleDecimal should be used. I'm just using C# ExecuteScalar to get an average out of a table's field.
Can someone show me a concrete-but-simple example of how to get an average w/o getting Arithmetic Overflow?
thanks much,
cdj

Hi,
If you want to use ExecuteScalar, you could wrap the AVG call with a call to ROUND or TRUNC to keep it under 28 digits. for example
select round(1/3,28) from dual;
Here's an example that gets 38 digits without overflow.
Hope it helps,
Greg
using System;
using System.Collections.Generic;
using System.Text;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
class Program
static void Main(string[] args)
using (OracleConnection con = new OracleConnection())
con.ConnectionString = "user id=scott;password=tiger;data source=orcl";
con.Open();
using (OracleCommand cmd = new OracleCommand())
cmd.CommandText = "select 1/3 from dual";
cmd.Connection = con;
using (OracleDataReader rdr = cmd.ExecuteReader())
while (rdr.Read())
Console.WriteLine(rdr.GetOracleDecimal(0).ToString());
}

Similar Messages

  • CAST Not working for me - Arithmetic overflow error converting int to data type numeric - error

    GPM is DECIMAL(5,2)
    PRICE is DECIMAL(11,4)
    COST is DECIMAL(7,2)
    Trying to update the Gross Profit Margin % field and I keep getting the "Arithmetic overflow error converting int to data type numeric" error.
    UPDATE SMEMODETAIL SET SMD_GPM = (SMD_PRICE-SMD_COST) / SMD_PRICE * 100
    FROM SMEMODETAIL WHERE SMD_PRICE<>0 AND SMD_QUANTITY<>0
    Example record:
    SMD_PRICE    SMD_COST    GPM%
    1.8500            1.62                12.4324324324324300
    I added cast and I still get the error.
    How do I format to get this to work?
    Thanks!

    Hi GBerthume,
    The error is caused by some value such as 1000.01 of the expression (SMD_PRICE-SMD_COST) / SMD_PRICE * 100 exceeds the
    precision of the column(DECIMAL(5,2)). The example data doesn't cause the overflow error for the value of the expression is 12.43 which is in the scope of DECIMAL(5,2).
    USE TestDB
    CREATE TABLE SMEMODETAIL
    SMD_PRICE DECIMAL(11,4),
    SMD_COST DECIMAL(7,2),
    SMD_GPM DECIMAL(5,2)
    INSERT INTO SMEMODETAIL(SMD_PRICE,SMD_COST) SELECT 1.8500,1.62
    UPDATE SMEMODETAIL SET SMD_GPM = (SMD_PRICE-SMD_COST) / SMD_PRICE * 100
    FROM SMEMODETAIL WHERE SMD_PRICE<>0-- AND SMD_QUANTITY<>0
    SELECT * FROM SMEMODETAIL
    DROP TABLE SMEMODETAIL
    The solution of your case can be either scale the DECIMAL(5,2) or follow the suggestion in Scott_morris-ga's to check and fix your data.
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Arithmetic overflow error converting expression to data type int

    Hi
        iam creating on sp for  the  database total size , used mb and  free size .  percentage free . 
     in  this purpose i was creating on sps, with in the sp iam was writing  one select statement . it  statement is    
    SELECT [Drivename] ,[DataSizedUsedMB],[DriveFreeSizeMB],DriveTotalSizeMB,
      CAST( (DriveFreeSizeMB/DriveTotalSizeMB)*  100 AS NUMERIC(5,2))
       As
      [PercentFree] ,[DateRecorded] FROM 
    SELECT SUBSTRING([physical_name],1,1) AS Drivename,
      CAST(((SUM(COALESCE(size,0)))*8)/1024 AS NUMERIC(20,2)) AS DriveTotalSizeMB,
      CAST(((SUM( COALESCE( FILEPROPERTY( [name],'SpaceUsed'),0)))*8)/1024 AS NUMERIC(20,2)) AS DataSizedUsedMB,
      CAST(((SUM(COALESCE(size,0))-SUM(COALESCE(fileproperty([name],'spaceused'),0)))*8/1024)AS NUMERIC(20,2)) AS DriveFreeSizeMB
      ,SYSDATETIME()  AS [DateRecorded]
    FROM sys.master_files 
    GROUP BY SUBSTRING([physical_name],1,1))  AS Data
      it was executive one  server with out error  but the same select  statement is writing antoher server iam geeting  belo error.
    "@ErrorDesc: Line 24 - Line 13- Arithmetic overflow error converting expression to data type int." 
      how to slove this issue..
    please help me...

    Change 8 to 8E0, to make it a float literal. The data type of
    SUM(COALESCE(size,0)))*8)
    is int, since all components are int, and it can easily overflow the size for an int. If you use 8E0, you get a float, and the entire expression will be float.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • MBVOutPut Error PopulateFromRecordset, Err msg :Arithmetic overflow error

    Hi all
    We are experiencing technical difficulties. ie We have an Orchestration based Web Service,
    That sporadically consumes  lots of Memory.
    An Initial Analysis with Message Box Viewer.. Shows the following msg below.
    Any idea how one, can Interpret the message, locate and fix it?
    Thank in Advance
    ERROR : PopulateFromRecordset, Err msg :Arithmetic overflow error
    converting int to data type numeric. (STAGE : Executing SQL Query)
    MSGBOX DB 1 (MASTER) "BizTalkMsgBoxDb" on zx1000\BizTalkServer
    Col1
    NULL
    1 Rows
    AKE

    Here is part of the scenario.
    Type: = WCF-Basic-Http
    SOAP Action Header
    <BtsActionMapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" mlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Operation Name="StartInsertBizTalk" Action="http://schemas.myOpertion.com/StartInsertBizTalk" />
    Request response via Web Service
    Send Pipeline = XMLTransmit
    ReceivePipeline = XMLReceive.
    The Orchestration sends message
    We receives a response.. However, as soon as the response arrive.
    The message hangs and the process start consuming up to  8 Gig of memory.
    Hope it helps
    AKE

  • Arithmetic Overflow error converting float to data type numeric

    Hi,
    Am facing strange issue,I have function which returns money datatype and assigning the return money value to float datatype in table.
    Error msg:
    Msg 8115, Level 16, State 6, Procedure GBCalcCatalogPriceNewV2, Line 204
    Arithmetic overflow error converting float to data type numeric.
    The statement has been terminated.
    Strange thing is the same stored procedure is working fine in production environment,but in the deveopment i see this error.Am scared if the same happens in the production environment.Please advice and advance
    thanks
    Regards
    RAj

    Strange thing is the same stored procedure is working fine in production environment,
    How could that be strange? This is an error that occurs depending on the data. Accidents that are waiting to happen will happen sooner or later.
    Then again, a development database may be more prone to such errors, because data that entered are completely out of whack with real life data. Still it is a warning sign. If you have some place where you convert data from float to numeric, you must consider
    the risk that the float value is outside the range for the numeric data type. How do you prevent that from happening? Maybe a CHECK constraint on the column? Of if the data origins from a money column, use a numeric data type with sufficient precision.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Arithmetic overflow error converting expression to data type int. Why in this case?

    Hi guys, it is Friday and I am really tired but..
    WITH CTE AS (
    SELECT LEN(CONS_ID) AS PROCA FROM TryCons)
    SELECT SUM(PROCA) FROM CTE
    Why I retrieve
    Arithmetic overflow error converting expression to data type int.
    Len should returns a number and so sum should work. It can be because I am trying to read  500 millions rows? But it wouldn't make sense.. 

    Len should returns a number and so sum should work. It can be because I am trying to read  500 millions rows? But it wouldn't make sense.. 
    If the average length of the field exceeds 4.29, that statement will explode. Since I don't know what's in CONS_ID, I can't say whether it makes sense or not. Although, I will have to say that from my uninitiated position, this seems like an
    accident to happen.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Arithmetic overflow error

    Hi all,
    The below is suppose to generate random dates but I receive the following error:
    Msg 8115, Level 16, State 2, Line 7
    Arithmetic overflow error converting expression to data type datetime.
    SQL Below - if is this happening?
    DECLARE
    @MinDate INT, @MaxDate INT;
    DECLARE
     @RANGE INT = DATEDIFF(DD, @MinDate, @MaxDate);
    SET @MaxDate =20141212
    SET @MinDate = 20140101
    SELECT CONVERT(DATE, DATEADD(DD, ROUND(RAND(CAST(NEWID() AS VARBINARY)) * @RANGE,0,-1), @MinDate));

    Reason is because you've declared variable as int. An integer value of 0 represents a base date of 19000101. SO maximum possible integer value you can convert to date is 2958463 which is why it throws error for values 20141212,20140101
    etc
    convert them to string and they all work fine
    DECLARE
    @MinDate INT, @MaxDate INT;
    SET @MaxDate =20141212
    SET @MinDate = 20140101
    DECLARE
    @RANGE INT = DATEDIFF(DD,CAST( @MinDate AS varchar(8)), CAST(@MaxDate AS varchar(8)));
    SELECT CONVERT(DATE, DATEADD(DD, ROUND(RAND(CAST(NEWID() AS VARBINARY)) * @RANGE,0,-1), CAST(@MinDate AS varchar(8))));
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • SQL 8115 : Arithmetic overflow error when running index analysis

    Hi experts,
      I got an error: "SQL 8115 : Arithmetic overflow error converting float to data type numeric
    row 1, col -1 [WP3 ] [sap_index_recommend:BUILD_N_E", please help.

    Hi João,
      It has been done.

  • Arithmetic Overflow Errors

    I remember that when Java was first introduced, one of the major design goals of the language was to eliminate common programmer errors. For example, instead of trusting the programmer to read the documentation of a given function to learn that they needed to test for a negative return value as an error, java included a very rigorous exception handling requirement. The developer who wrote a method would declare which exceptions it could throw and those using the method were required to account for those exceptions.
    I'm now starting to work with Java on a full time basis and was reviewing the arithmetic rules. I couldn't believe it when I discovered that overflowing an integer value doesn't cause an arithmetic overflow error!
    Am I missing something, or is that a major deviation from the stated language design goals?!

    David.Wendelken wrote:
    I remember that when Java was first introduced, one of the major design goals of the language was to eliminate common programmer errors. For example, instead of trusting the programmer to read the documentation of a given function to learn that they needed to test for a negative return value as an error, java included a very rigorous exception handling requirement.Uhhh... not quite - programmers do have to read the documentation nevertheless, because otherwise they don't know what the result of a call or valid parameters would be.
    The developer who wrote a method would declare which exceptions it could throw and those using the method were required to account for those exceptions.Yeah...
    I'm now starting to work with Java on a full time basis and was reviewing the arithmetic rules. I couldn't believe it when I discovered that overflowing an integer value doesn't cause an arithmetic overflow error!Why should it?
    Am I missing something, or is that a major deviation from the stated language design goals?!Your design goals are a little off. Nobody aimed to make Java to be usable without reading the docs/specs. They aimed at keeping things simple and cleanly designed, not exactly as self-explanatory. There are many things in the JLS that aren't.

  • What is the error code mean? And how to solve it ?Please give your answer. Thanks

    What is the error code  mean? And how to solve it ?Please give your answer. Thanks
    Attachments:
    QQ截图20140403134626.png ‏59 KB

    duplicate post
    LabVIEW Champion . Do more with less code and in less time .

  • I get an error in using ncWatiForS​tate,how to solve the problem?

    I recuperate a  CVI code (obj2obj) in examples, in order to receive CAN data. However, I met an ERROR, 
    It shows:
    (Hex 0xBFF62001) means the timeout of a wait or notification function expired before any desired state occurred.
    Solutions: Increase value of Timeout parameter; Verify your cable connections and operation of remote devices
    But if the other OBJ didn't  send data,how to solve this ERROR?
    I means that i want to get my program continue  running without/after this error be solved?That is if time is out,it jumps to next line。

    You could ignore the timeout for the wait and just case to the next function you wnat to call if a timeout ocures. Thus you would not call the read function in a timeout case.
    Or you could loop into the wait function again to wait another timout until the frame you expected has received.
    DirkW

  • HTML DB Color Error message in a field - how to set them

    Hi everyone,
    I want to know where I can set the color of an error message in a field ?
    In our page model, on an required field: the message is black
    and on an optional field: the message is red.
    I want both of them red.
    Thank you. Bye.

    Hi Carl,
    I have a similar issue. I am using Theme 20 and error messages per item as well as page level error messages are coming up in Blak. Is there a way to show them in Red?
    Thanks,
    Bhavesh

  • Quickly!Quickly!Quickly!What is the error code mean? And how to solve it ?Please give your answer. Thanks

    What is the error code mean? Why is there an error?And how to solve it ?Please give your answer. Thanks!                                               
    ——1110340026
    Attachments:
    QQ图片20140403140655.jpg ‏108 KB

    Sannieboyyyy wrote:
    Could be me, but your VI is not working properly on the english version of LV. Can I suggest you to try programming in English in the future?
    Yes, it's you. The VI is working just fine, except for some cosmetic issues with the labeling. I don't think is is a valid suggestion to force somebody to program in a specific language, especially since LabVIEW supports all these languages.
    Here are the problems with the VI:
    If you don't want an amplitude of zero, you need to set the amplitude control to a nonzero value before running. Simple as that!. (You could also set the input range for the amplitude control to exclude zero or use a case structure to skip certain code if the amplitude is zero).
    You could also wire the error output to an indicator so it simply displays the errors, but keeps running.
    Your while loop is currently useless. You can delete it and the program function will not change. Use a stop button at the loop condition.
    Your while loop needs some timing so it runs at a reasonable rate. Either add a small wait or configure the signal generation to "simulate acquisition timing" instead of "run as fast as possible".
    LabVIEW Champion . Do more with less code and in less time .

  • 10.6.5, then Error -36 on external HD : How to solve now?

    It's probably just a coincidence, but a day after upgrading to 10.6.5 I started getting Error -36's on one of my external drives (the one that has my iTunes library on it.) The drive is one of those LaCie Mini hubs, 250 GB.
    What I've tried so far:
    - Dragging files over to another external individually. This sometimes works.
    - Using dot_clean on some of the directories in Terminal. This has not solved problems.
    - Trying to move the files using Terminal. Terminal could not move the files.
    - Unmounting and verify/repairing disk in Disk Utility. Disk Utility reports no problems with the drive.
    - Running Time Machine for the first time (I bought a 1 TB external in September and didn't think about how I have the space for Time Machine until today). Time Machine got about 40 GB in (out of 220) and reported an error and said - paraphrasing - "perhaps try again later."
    So now I'm letting the drives -- all three of them -- sit turned off for the day, wondering what my next step should be in trying to recover the contents on that HD. Thoughts?

    MojaveNC wrote:
    - Running Time Machine for the first time (I bought a 1 TB external in September and didn't think about how I have the space for Time Machine until today). Time Machine got about 40 GB in (out of 220) and reported an error and said - paraphrasing - "perhaps try again later."
    That's most likely Time Machine trying to back up whatever's wrong/corrupted on the iTunes drive. You should be able to see the actual message, via #C2 in [Time Machine - Troubleshooting|http://web.me.com/pondini/Time_Machine/Troubleshooting.html] (or use the link in *User Tips* at the top of this forum). It's probably "An error occurred while copying files to the backup volume." Whatever it is will probably be fixed when you fix the iTunes drive.
    What do you mean by "Terminal could not move the files"?
    Was there an error message? If so, what?
    That sort of problem is usually associated with the drive, or the connections to it. Eject and disconnect it, and disconnect anything connected to it.
    Restart your Mac, connect the drive. Make sure all connections are snug and secure, and power it on. Do a +*Repair Disk+* on it again.
    Also make sure it's plugged-in to a known good outlet or surge protector (or, better, U.P.S. system), preferably the same one the Mini is on.
    If that doesn't help, if it's connected to your Mac via USB, try via FireWire, and vice-versa.
    If the problem continues, eject and disconnect it. Try different port(s), cables, and combinations (a plug that works fine in one port may not make good contact in another).
    How old is it?

  • Can't restore or update my Ipod Touch 4g. when I want to update it, I have error 3194 or 2009. How to solve this problem?

    I have a problem. When i try to update, restore or fully clear memory of Ipod, i always have an error. I can't do anything with it. during my efforts, i had errors like 3194, 2134 or 2009 and another. Help me please. Sorry for my bad english, i'm from Ukraine.

    3194
    See the actions for that error here:
    iTunes: Specific update-and-restore error messages and advanced troubleshooting
    iPhone Error 3194 - How to Fix iTunes Error 3194?
    Fix Error 3194 from iTunes during iPhone restore
    Error 2000-2009 (2001, 2002, 2005, 2006, 2009, and so on)
    If you experience this issue on a Mac, disconnect third-party devices, hubs, spare cables, displays, reset the SMC, and then try to restore. If you are using a Windows computer, remove all USB devices and spare cables other than your keyboard, mouse, and the device, restart the computer, and try to restore. If that does not resolve the issue, try the USB issue-resolution steps and articles listed for Error 1604 above. If the issue persists, it may be related to conflicting security software. If the errors persist on another computer and known-good USB cable, the device may need service.
    The "device may need service" means a hardware problem. In that case make an appointment at the Genius Bar of an Apple store.
    Apple Retail Store - Genius Bar

Maybe you are looking for

  • Updating data in mulitple databases

    Hi, I have a requirement in my project to update the data in two databases, when user updates data in the screen and saves it. We are using stateless session EJB to call the DAO. The update is using normal JDBC update statement. If some thing goes wr

  • Ringtone not synching

    i have purchased a ringtone off of itunes and it's showing up under my library as a ringtone, so i know i did that part correctly. after synching to my iphone, the ringtone is showing up in my ipod but it's not showing up under settings...sounds. nor

  • Sync z30 with PC does not transfer data to the PC

    i've installed BBlink in a PC with windows 7 and the contacts/calendar sync with outlook does not go well. It apears a message that sync is complete but no dta as been trasfered to the PC

  • Viewing videos in iPhoto

    Just downloaded Snow L. and now I can't simply double click on videos to run in the new Quicktime. Any suggestions. I have iLife '08. Was I supposed to know that it doesn't work with Snow? Got tons of video that I can't see. Sure I can go the long wa

  • PSE 7 empty folder

    I just purchased 7 (subject of another thread), imported files into a newly created subfolder (and they are there in Win Expl)and when the window that shows only the new files had none (had the same problem with 6) I pressed show all, highlighted the