我正在尝试将 oracle 数据库应用程序迁移到 postgres。 我似乎无法在 postgres 中找到 NANVL 的等价物。有什么方法可以模拟吗?
来自Oracle manual :
The NANVL function is useful only for floating-point numbers of type BINARY_FLOAT or BINARY_DOUBLE. It instructs Oracle Database to return an alternative value n1 if the input value n2 is NaN (not a number). If n2 is not NaN, then Oracle returns n2.
最佳答案
在 Postgres 中,您可以将数值与特殊常量 'NaN'
进行比较:
select some_column = 'NaN'
from some_table;
因此您可以编写一个函数来实现 nanvl()
:
create function nanvl(p_to_test numeric, p_default numeric)
returns numeric
as
$$
select case
when p_to_test = 'NaN' then p_default
else p_to_test
end;
$$
language sql;
关于oracle - 什么是 postgres 中的 NANVL(oracle 函数)的等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44665175/