Sid*_*Sid 1 sql oracle threshold
我们正在构建一个报告,其中将一些值与阈值进行比较。逻辑是
if value > lower_threshold and value < upper_threshold then PASS else FAIL
Run Code Online (Sandbox Code Playgroud)
但是,对于某些参数,upper_thresholds设置为NULL。从本质上讲,这意味着没有上限,如果值<= lower_threshold,则只会失败,否则将始终为PASS。我们正在使用Oracle SQL构建查询。由于将任何值与NULL进行比较将始终返回FALSE,因此报表无法正常工作。一种选择是:
if value > lower_threshold and value < nvl(upper_threshold, 9999999999999999) then PASS else FAIL
Run Code Online (Sandbox Code Playgroud)
这不是一个好方法。还有其他选择可以达到相同目的吗?
or 想到:
if value > lower_threshold and (value < upper_threshold or upper_threshold is null) then PASS else FAIL
Run Code Online (Sandbox Code Playgroud)
当然,对于表达式,您将使用case并在where子句中进行过滤:
where value > lower_threshold and (value < upper_threshold or upper_threshold is null)
Run Code Online (Sandbox Code Playgroud)