如何在sql查询中获取精度长度

问题描述 投票:0回答:2

我需要得到例外值的精度长度。

例如:如果我的值为 1000343.345 我想要输出点后的长度 (345)

预期输出为::3 长度为 345

谢谢

oracle11g oracle-sqldeveloper oracle-apex plsqldeveloper plsql-package
2个回答
0
投票

例如:

SQL> with test (col) as
  2    (select 1000343.345 from dual union all
  3     select     500.2   from dual union all
  4     select    1234     from dual union all
  5     select -239422.13  from dual
  6    )
  7  select col,
  8         length(col - floor(col)) - 1 result       --> this
  9  from test;

       COL      RESULT
----------  ----------
1000343,345          3
      500,2          1
       1234          0
 -239422,13          2

SQL>

0
投票

您可以使用一个老技巧,即从数字本身中减去底值。然后得到它的长度并减少1:

select length(1000343.345 - floor(1000343.345)) -1 from dual;
© www.soinside.com 2019 - 2024. All rights reserved.