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>
.
CodePudding user response:
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.