【发布时间】:2019-11-02 00:43:26
【问题描述】:
在 Oracle 11.2.0.4... 给定表 A 有一个长的 varchar 列,其中包含文本段落,我想检查该文本中的任何单词是否存在于具有单数单词垂直列表的表中。 我正在寻找一种在单个查询中执行此操作的方法,而不是使用游标。
基本上,我认为我需要将段落分成单词,然后加入垂直单词表,但不知道如何进行。
Example:
TableA:
+----+--------------------------------------------+
| id | comments |
+----+--------------------------------------------+
| 1 | This sentence has no reference to any word |
| 2 | But this one references jungle |
| 3 | And this one references Trees |
+----+--------------------------------------------+
TableB:
+----+---------+
| id | word |
+----+---------+
| 1 | Jungle |
| 2 | Forest |
| 3 | Trees |
| 4 | Animals |
| 5 | River |
+----+---------+
鉴于这些表,我想要一个 SQL 查询,它会告诉我表 A 的第 2 行和第 3 行包含表 B 中存在的单词。
我研究过使用 xmltype 功能将表格拆分为单词,然后像这样将它们连接在一起:
select id,
(select count(1) from tableb f, xmltable(
'/r/c/text()'
passing xmltype('<r><c>'||replace((regexp_replace(comments, '[^a-z][^A-Z]')), ' ', '</c><c>')||'</c></r>')
columns subs varchar2(4000) path '.'
) s where trim(f.word) = trim(s.subs)) words_found, comments
from tablea
where trim(comments) is not null
但这不是很好。它在失败之前只能处理一小部分注释行。
提前致谢,如果已得到解答,我深表歉意。我做了很多检查,但没有找到我要找的东西。
【问题讨论】: