首页 > 解决方案 > 如何通过某个 Round up 因子进行 Roundup?

问题描述

If x = 1.71 Then output = 1
If x = 1.82 Then output = 2

我的综合因素是0.8

如何在 Oracle 存储过程计算中实现这一点?

标签: plsqloracle11g

解决方案


从您提供的最小示例中,您希望ceil()使用调整后的值:

ceil(x - 0.8)

在 CTE 中包含一些示例值的演示:

with t (x) as (
  select 1.5 + (level - 1)/10 from dual connect by level <= 5
  union all select 1.71 from dual
  union all select 1.78 from dual
  union all select 1.79 from dual
  union all select 1.81 from dual
  union all select 1.82 from dual
)
select x, ceil(x - 0.8)
from t
order by x;

         X CEIL(X-0.8)
---------- -----------
       1.5           1
       1.6           1
       1.7           1
      1.71           1
      1.78           1
      1.79           1
       1.8           1
      1.81           2
      1.82           2
       1.9           2

目前还不清楚 1.8 会发生什么。

在 PL/SQL 中你可以做同样的事情:

y := ceil(x - 0.8);

推荐阅读