Sql 如何在查询中使用LIKE查找多个单词?

Sql 如何在查询中使用LIKE查找多个单词?,sql,oracle,sql-like,textmatching,Sql,Oracle,Sql Like,Textmatching,我有一张顾客桌 id name class mark 1 John Deo Matt Four 75 2 Max Ruin Three 85 3 Arnold Three 55 4 Krish Star HN Four 60 5 John Mike Four 60 6 Alex John Four 55 我想搜索一个客户,该客户可能被命名为Joh

我有一张顾客桌

id  name           class    mark

1   John Deo Matt   Four    75
2   Max Ruin        Three   85
3   Arnold          Three   55
4   Krish Star HN   Four    60
5   John Mike       Four    60
6   Alex John       Four    55
我想搜索一个客户,该客户可能被命名为
John Matt
,而不包含
deo
字符串。如何使用类似的条件进行此操作

SELECT * FROM cust WHERE name LIKE '%John Matt%'
结果应获取第1行

如果搜索字符串是
Matt Deo
john


在尝试查找确切名称时,无法实现上述功能。即使给定了两个字符串,我如何进行LIKE查询来获取客户?

如果要匹配的模式为

string1<space>anything<space>string2
为什么不是这个

select * from cust where name Like 'John%Matt' ;

您必须像一样使用
?Oracle有很多更强大的搜索选项


我会看看的。

我相信您需要类似REGEXP_()的代码:


这里,正则表达式字符串指定名称包含“matt”或“deo”,而“i”表示不区分大小写。名字的顺序无关紧要

%是一个通配符。那么像“John%Matt”这样的名字在哪里会匹配“John something Matt”@Rene,但是如果
Matt Deo
必须搜索怎么办?
select*from cust where name像“%John%Matt%”不要忘记Oracle会检查单词大小写(区分大小写)。@RubahMalam在
如“%Matt%John%”时不起作用。
当然,您可以提供不起作用的示例。然而,给出的答案确实适用于您原来的问题。也许你必须更新你的问题并更好地指定你的要求。如果搜索字符串给定
Matt Deo
看看你是否可以重写我的声明以满足你的需要。您可以随时添加或。。。要匹配string1 | |“”| | string2。
select * from cust where name Like 'John%Matt' ;
 SELECT *
   FROM custtable
  WHERE upper(NAME) LIKE '%' || upper(:first_word) || '%'
    AND upper(NAME) LIKE '%' || upper(:second_word) || '%'
SQL> with tbl(name) as (
      select 'John Deo Matt' from dual
    )
    select name
    from tbl
    where regexp_like(name, 'matt|deo', 'i');

NAME
-------------
John Deo Matt

SQL>