0

I have a table in the (oracle) database that has a column of NUMBER(12). I can't use int in C# because that is small, so I used long. But long is too big for this table column. Is there any way to limit the size of a long before I send the data to the database? Otherwise I will get an error ORA-21525, since I exceed the size of the table column. The data send to the database is actually a List<long>.

7
  • 3
    Show us how you declared your parameter in your well parameterized sql query, show us the table def, the code that invokes the query and an example of the data that causes the problem. If your example data is a long of 1234567890123 then it's really going to be c#'s job to not send numbers greater than 999,999,999,999..
    – Caius Jard
    Nov 3, 2021 at 6:45
  • Where do you get your values from? Nov 3, 2021 at 6:45
  • 1
    What will you do with longs that exceed, by the way?
    – Caius Jard
    Nov 3, 2021 at 6:51
  • Wrap the long in a struct and use Value Conversion if you are using EF. Other wise in your constructor add a check. Nov 3, 2021 at 6:54
  • whatever type you are using in C#, why are you trying to insert numbers bigger than the precision allowed in the column ? where those numbers are coming from ? Either you have data which does not fit your column size, thus change the precision in the column, or you are inserting numbers that should not be inserted, thus discard them Nov 3, 2021 at 7:18

1 Answer 1

2

The most obvious solution would be to use a custom number type that restricts the range of values for the number. Something like

public readonly struct Number12{
    public long Value {get;}
    public Number12(long num){
        if(num > 999999999999 || num < -999999999999 ){
           throw new ArgumentException("number out of rage " +num);
        }
        Value = num;
    }
   // Add operators, conversions etc
}

An advantage of this would be that it is obvious that this number has some special rules. But it will be more cumbersome to use, and may cause issues if the database is changed in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.