Regex查找两个字符串之间的常用单词数(Oracle)? [关闭]

问题描述 投票:-4回答:1
我正在Oracle DB中编写一个QUERY,在这里我需要使用regx在两个字符串之间找到常用词。

说有两个字符串:

String 1:'group global Tissue' String 2:'GLOBAL TISSUE GROUP INC'

计数应为

3。因为全局,组织和组在这两个字符串之间是公用的。注意:匹配不区分大小写。

regex oracle
1个回答
0
投票
这里是一个选择:

    [t1 CTE将第一个字符串分成几行
  • t2对第二个字符串所做的相同
  • 结果计数匹配的“单词”(转换为小写,以便GLOBALglobal匹配)
  • is not null条件是
  • 不计数单词之间的多个空格

SQL> with test (col1, col2) as 2 (select 'group global Tissue', 'GLOBAL TISSUE GROUP INC' from dual), 3 t1 as 4 (select lower(regexp_substr(col1, '[^ ]+', 1, level)) val1 5 from test 6 connect by level <= regexp_count(col1, ' ') + 1 7 ), 8 t2 as 9 (select lower(regexp_substr(col2, '[^ ]+', 1, level)) val2 10 from test 11 connect by level <= regexp_count(col2, ' ') + 1 12 ) 13 select count(*) 14 from (select val1 from t1 where val1 is not null 15 intersect 16 select val2 from t2 where val2 is not null 17 ); COUNT(*) ---------- 3 SQL>
© www.soinside.com 2019 - 2024. All rights reserved.