NVL 替换空值

SELECT a column_with_null, NVL(a, 'N/A') column_without_null FROM
  (SELECT NULL a FROM DUAL);
COLUMN_WITH_NULL COLUMN_WITHOUT_NULL
(空值) N / A

NVL 可用于比较两个可包含 NULL 的值:

SELECT
    CASE WHEN a = b THEN 1 WHEN a <> b THEN 0 else -1 END comparison_without_nvl,
    CASE WHEN NVL(a, -1) = NVL(b, -1) THEN 1 WHEN NVL(a, -1) <> NVL(b, -1) THEN 0 else -1 END comparison_with_nvl
  FROM
    (select null a, 3 b FROM DUAL
     UNION ALL
     SELECT NULL, NULL FROM DUAL);
COMPARISON_WITHOUT_NVL COMPARISON_WITH_NVL
-1 0
-1 1