oracle - 什么是 postgres 中的 NANVL(oracle 函数)的等价物

标签 oracle postgresql database-migration

我正在尝试将 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/

相关文章:

postgresql - 为什么 HikariCP 在 postgresql 中创建如此多的空闲连接

ruby-on-rails - 列删除后出现 Rails DB heroku 迁移错误

php - 在没有 CREATE 权限的情况下将 SQL 转储导入到 Typo3 安装中

laravel - 无法使用 laravel 数据库迁移创建外键

mysql - 如何避免重复的列值

java.sql.BatchUpdateException : ORA-01849: hour must be between 1 and 12

sql - 使用子查询进行比较

sql-server - 使用 "WHERE A=1 OR A=2 clause"SELECT 查询糟糕的执行计划

SQL 按分组排序

java - 检查日期数据库并执行