1

我有一个字符串'from+google+world'

对于我们正在使用的单个查询,我需要在任何地方搜索整个三个关键字的文本,

select * from tabl name 
where desc like '%from%' 
and desc like '%google%' 
and desc like '%world%'

如何拆分字符串并将其与上述查询一起使用。 @p1+@p2+@p3

select * from tabl name 
where desc like '%@p1%' 
and desc like '%@p2%' 
and desc like '%@p3%'

Radu Gheorghiu:这个命令有 50% 的帮助,它只是用 De-Limiter 拆分字符串很好' 和 desc 不像'所有@p3 的事情都是@p1 很好'

4

3 回答 3

2

这是您需要的代码,这是一个 SQLFiddle

with test as 
    (select 'from+google+world' str from dual  
    )  
    select regexp_substr (str, '[^+]+', 1, rownum) split  
    from test  
    connect by level <= length (regexp_replace (str, '[^+]+'))  + 1
于 2013-07-30T05:29:54.317 回答
1

你是说这个输出??

from
google
world

WITH t AS (SELECT 'from+google+world' word FROM dual)
SELECT regexp_substr(word, '[[:alpha:]]+', 1, LEVEL) FROM T
CONNECT BY regexp_substr(word, '[[:alpha:]]+', 1, level) is not null;

你是说这个输出??

from
google
world

WITH t AS (SELECT 'from+google+world' word FROM dual)
SELECT regexp_substr(word, '[[:alpha:]]+', 1, LEVEL) FROM T
CONNECT BY regexp_substr(word, '[[:alpha:]]+', 1, level) is not null;

或者,如果您在包含任何这些单词的表中搜索,您可以CONTAINS从索引的 oracle 中运行:

链接在这里:http ://docs.oracle.com/cd/B28359_01/text.111/b28303/query.htm

CTXCAT在这里搜索:http ://www.oracle.com/technetwork/database/enterprise-edition/ctxcat-primer-090555.html

于 2013-07-30T05:29:44.353 回答
0
SELECT * FROM tablename WHERE desc IN (
    SELECT regexp_substr('from+google+world','[^+]+', 1, level) FROM dual
    CONNECT BY regexp_substr('from+google+world', '[^+]+', 1, level)
    is not null
);
于 2013-07-30T05:39:52.947 回答