如何在 where/in 语句中使用物化子查询?

How to use a materialized subquery inside where/in statement?

有如下语句:

WITH tokenkeys 
as
(
    select regexp_substr('A set of words from other side','[^ ]+', 1, level) WORDSPLIT from dual
    connect by regexp_substr('A set of words from other side', '[^ ]+', 1, level) is not null
)
select * from tokenkeys

它输出一个 table 像:

|WORDSPLIT|
|A        |
|set      |
|of       |
|words    |
|from     |
|other    |
|side     |

我想在 where/in 语句中使用这个临时集合:

WITH tokenkeys 
as
(
    select regexp_substr('A set of words from other side','[^ ]+', 1, level) WORDSPLIT from dual
    connect by regexp_substr('A set of words from other side', '[^ ]+', 1, level) is not null
)
select p.* from people p
where 
p.name in (tokenkeys.wordsplit)
or UTL_MATCH.EDIT_DISTANCE_SIMILARITY(p.lastname, tokenkeys.wordsplit) > 60 ???
or ....

我有两个问题:

  1. 怎么做p.name in (tokenkeys.wordsplit)?
  2. 如何将临时集合与 edit_distance_similarity 函数混合,并获得最大结果:

示例:

UTL_MATCH.EDIT_DISTANCE_SIMILARITY(p.lastname, tokenkeys.wordsplit) > 60
                                    //I want the greater

max(UTL_MATCH.EDIT_DISTANCE_SIMILARITY(p.lastname, tokenkeys.wordsplit))
                                    //I can't yet test this line.

非常感谢。

use join with distinct (将where子句转入连接条件-on):

WITH tokenkeys 
as
(
    select regexp_substr('A set of words from other side','[^ ]+', 1, level) WORDSPLIT from dual
    connect by regexp_substr('A set of words from other side', '[^ ]+', 1, level) is not null
)
select distinct p.* from people p
join tokenkeys on p.name in (tokenkeys.wordsplit)
or UTL_MATCH.EDIT_DISTANCE_SIMILARITY(p.lastname, tokenkeys.wordsplit) > 60