Ifozest
Ifozest

Reputation: 967

It is possible to get by query maximum input NUMBER value in column?

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

Answers (3)

jarnbjo
jarnbjo

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

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136092

try this

    ResultSet rs = ...
    ResultSetMetaData md = rs.getMetaData();
    int precision = md.getPrecision(column);
    int scale = md.getScale(column);

Upvotes: 2

Arpit
Arpit

Reputation: 12797

select max(column_name) as 'Max_number' from table_name

Upvotes: 0

Related Questions