Oracle SQL 列比较

Oracle SQL column comparison

我有两列,我想比较一下它们是否相等,问题是相同的关键字以不同的方式书写。

例如,如果 column_1 = 123 Maryland Ave 和 column_2 = 123 Maryland Avenue 这两列应该相等,我想在查询中创建第三列以显示它们是否是否相等,谢谢您的帮助!

Column_1                   Column_2                  Equal?
-----------------------------------------------------------
 123 Maryland Ave           123 Maryland Avenue       Yes
 456 Maryland Ave           123 Maryland Ave          No

一个选项是检查这些值之间的相似性

SQL> with test (id, col1, col2) as
  2    (select 1, '123 Maryland Ave', '123 Maryland Avenue' from dual union all
  3     select 2, '456 Maryland Ave', '123 Maryland Ave'    from dual
  4    )
  5  select id, col1, col2,
  6    utl_match.jaro_winkler_similarity(col1, col2) as sim
  7  from test;

        ID COL1             COL2                       SIM
---------- ---------------- ------------------- ----------
         1 123 Maryland Ave 123 Maryland Avenue         96
         2 456 Maryland Ave 123 Maryland Ave            87

SQL>

现在,您必须确定满足您需求的阈值。是90%吗?让我们假设它是。然后你会使用 CASE 表达式:

SQL> with test (id, col1, col2) as
  2    (select 1, '123 Maryland Ave', '123 Maryland Avenue' from dual union all
  3     select 2, '456 Maryland Ave', '123 Maryland Ave'    from dual
  4    )
  5  select id, col1, col2,
  6    case when utl_match.jaro_winkler_similarity(col1, col2) > 90 then 'Yes'
  7         else 'No'
  8    end as equal
  9  from test;

        ID COL1             COL2                EQUAL
---------- ---------------- ------------------- -------
         1 123 Maryland Ave 123 Maryland Avenue Yes
         2 456 Maryland Ave 123 Maryland Ave    No

SQL>