首页 > 解决方案 > Oracle:比较两个不同表中没有主键的字符串列以查找匹配/不匹配的字符串

问题描述

我有两个表,我们想比较这些表中的两个字符串列。这些表中没有与 where 子句匹配的主键。表格如下: 比较应该忽略:

  1. 忽略字符串中任何位置的空格 2) 忽略区分大小写

在此处输入图像描述

输出需求:

在此处输入图像描述

标签: sqloraclejoinplsql

解决方案


您可以在连接条件中使用full outer joinwithupperreplacefunction,如下所示:

Select t1.str, t2.str,
       Case when t1.str is not null and t2.str is not null then 'exist in both table'
             when t1.str is not null then 'missing in table2'
             Else 'missing in table1'
       End as differences
From table1 t1 full join table2 t2
  On upper(replace(t1.str,' ','') = upper(replace(t2.str,' ','')

推荐阅读