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

时间:2015-02-26 22:27:53

标签: sql oracle plsql subquery edit-distance

有以下声明:

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

输出如下表格:

|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函数混合,并获得最大结果:
  3. 示例:

    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.
    

    非常感谢。

1 个答案:

答案 0 :(得分:0)

joindistinct一起使用(将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