Oracle中Like与Contains()之间的搜索条件差异 [英] search criteria difference between Like vs Contains() in oracle
问题描述
我创建了一个包含两列的表格.我插入了两行.
I created a table with two columns.I inserted two rows.
id name
1 narsi reddy
2 narei sia
一个是简单的数字类型,另一个是CLOB类型.因此,我决定在其上使用索引.我通过使用contains对此进行了查询. 查询:
one is simply number type and another one is CLOB type.So i decided to use indexing on that. I queried on that by using contains. query:
select * from emp where contains(name,'%a%e%')>0
2 narei sia
我希望2个人会来,但不会.但是,如果我给与喜欢,就给了我想要的东西. 查询:
I expected 2 would come,but not. But if i give same with like it's given what i wanted. query:
select * from emp where name like '%a%e%'
ID NAME
1 (CLOB) narsi reddy
2 (CLOB) narei sia
2 rows selected
最后,我了解到,就像在搜索整个文档或段落一样,但是包含的是用文字查找.
finally i understood that like is searching whole document or paragraph but contains is looking in words.
那么我如何获得所需的输出?
so how can i get required output?
推荐答案
LIKE和CONTAINS是根本不同的搜索方法.
LIKE and CONTAINS are fundamentally different methods for searching.
喜欢非常简单的字符串模式匹配器-它识别两个通配符(%)和(_),它们分别匹配零个或多个或正好一个字符.在您的情况下,%a%e%匹配表中的两条记录-它查找零个或多个字符,后跟a
,然后零个或多个字符,后跟e
,然后零个或多个字符.它的返回值也非常简单:返回匹配"或不匹配"-不显示灰色阴影.
LIKE is a very simple string pattern matcher - it recognises two wildcards (%) and (_) which match zero-or-more, or exactly-one, character respectively. In your case, %a%e% matches two records in your table - it looks for zero or more characters followed by a
, followed by zero or more characters followed by e
, followed by zero or more characters. It is also very simplistic in its return value: it either returns "matched" or "not matched" - no shades of grey.
内容功能强大使用上下文索引的搜索工具,该工具构建了一种词树,可以使用CONTAINS搜索语法进行搜索.它可以用于搜索单个单词,单词的组合,并且具有自己的丰富语法,例如布尔运算符(AND,NEAR,ACCUM).它也更强大,它返回一个分数",而不是返回简单的匹配"或不匹配",可用于按相关性对结果进行排名;例如对于包含两个单词并排很近的文档,CONTAINS(col,'dog NEAR cat')将返回较高的分数.
CONTAINS is a powerful search tool that uses a context index, which builds a kind of word tree which can be searched using the CONTAINS search syntax. It can be used to search for a single word, a combination of words, and has a rich syntax of its own, such as boolean operators (AND, NEAR, ACCUM). It is also more powerful in that instead of returning a simple "matched" or "not matched", it returns a "score", which can be used to rank results in order of relevance; e.g. CONTAINS(col, 'dog NEAR cat') will return a higher score for a document where those two words are both found close together.
这篇关于Oracle中Like与Contains()之间的搜索条件差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!