Reputation: 967
For example i have a table with column "example" NUMBER(5,2), if I right - max input value is 999,99.
It's possible get by query value that could be stored in that column? May be any SQL query or by java api?
Upvotes: 2
Views: 441
Reputation: 34323
If you already have the values for precision and scale, you should be able to calculate the maximum value like this:
int precision = 5;
int scale = 2;
double maxValue = (Math.pow(10, precision) - 1) / Math.pow(10, scale);
If you don't know the values for precision and scale, you can query the database metadata:
ResultSet rs = conn.getMetaData().getColumns("", "%", "{TABLENAME}", "{COLUMNNAME}");
if(!rs.next()) {
// unknown table/column
}
int precision = rs.getInt("COLUMN_SIZE");
int scale = rs.getInt("DECIMAL_DIGITS");
Upvotes: 1
Reputation: 136092
try this
ResultSet rs = ...
ResultSetMetaData md = rs.getMetaData();
int precision = md.getPrecision(column);
int scale = md.getScale(column);
Upvotes: 2