How to find out the number of digits of an oracle number
How about....
SELECT LENGTH(TRANSLATE(TO_CHAR(3.0123456789),'1234567890.-','1234567890'))
FROM dual
The translate simply removes the non numeric characters .-
Comments
-
Ioan Paul Pirau over 3 years
I have a table in oracle that looks like this:
name | type | nullable ------------------------------------------ person_name | varchar(20) | yes weight_coeficient | number | yes ...
How can I figure out how many digits a value of weight_coeficient has ? For example:
3.0123456789
has 11 digits (precision = 11) and 10 digits after the decimal (scale = 10)Is there any sql command/function that does that, something like
GetPrecision( select.. )
that returns 11 ?Note also that the definition of the table does not specify scale and precision. So as far as I know the maximum precision is applied for all the numbers. So I'm not interested in finding out the precision (= 48) of the definition, but the precision of a specific value in the table. Is that possible just using oracle commands ?
Thank you in advance,
JP -
Ioan Paul Pirau over 12 yearsThank you for the answer. But
3.0123456789
was an example. How can I adapt the code you wrote to useweight_coeficient
instead considering that the table name isCoeficients
? I would expect something likeSELECT LENGTH(TRANSLATE(Select weight_coeficient from Coeficients where name = 'John Paul'),'1234567890.-','1234567890')) FROM dual
or something. But this doesn't work. Sorry.. I'm not too good at sql sintax -
Allan over 12 years@John Paul: You'd be much better off with
SELECT LENGTH(TRANSLATE(weight_coeficient),'1234567890.-','1234567890')) from Coeficients where name = 'John Paul';
-
SiliconBadger about 6 years@Allan: good tip, but you have an extra parenthesis. I think it should be
SELECT LENGTH(TRANSLATE(weight_coeficient,'1234567890.-','1234567890')) from...