Skip to content
Advertisement

ResultSetMetaData getScale returns 0

I have a table called RATE_HISTORY with a field called RATE.
The RATE field has scale 18.
I am using ResultsetMetaData to get meta-data of columns in this table on Oracle 11.2.
I execute the following query in my code:

select (RATE * 100) from RATE_HISTORY

When I do metadata.getScale(), it returns 0. However, if I execute this query:

select RATE from RATE_HISTORY

getScale returns the correct value (18).
Is there a way to multiply two numbers in oracle and keep the scale?

Advertisement

Answer

Casting the result in the select should also work, the downside is that you have to repeat the scale from the column definition:

select cast(RATE * 100 as number(30, 18)) from RATE_HISTORY
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement