PL-SQL 中的 contains() 是如何工作的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2431054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How does contains() in PL-SQL work?
提问by Artic
Have a lot of unnecessary results using contains() method in my query. Don't tell me to use like or something else. It is hardcoded and couldn't be changed.
在我的查询中使用 contains() 方法有很多不必要的结果。不要告诉我使用喜欢或其他东西。它是硬编码的,无法更改。
回答by rosscj2533
Contains is used on text fields that have a 'CONTEXT Index', which indexes a text field for searching. The standard usage is like this (using the score
operator to display what is returned from the contains
clause based on the 1 in contains
matching the 1 in score
):
包含用于具有“CONTEXT 索引”的文本字段,该索引可索引用于搜索的文本字段。标准用法是这样的(使用score
运算符contains
根据contains
匹配 1 in中的 1来显示从子句返回的内容score
):
SELECT score(1), value
FROM table_name
WHERE CONTAINS(textField, 'searchString', 1) > 0;
For data like this in table table_name
对于表中这样的数据 table_name
value | textField
-------|-----------------------------------------------
A | 'Here is searchString. searchString again.'
B | 'Another string'
C | 'Just one searchString'
That query would return
该查询将返回
2 A
1 C
So contains is similiar to like, but will count how many times a string occurs in a text field. I couldn't find a resource using Contains the way it is used in the query you posted, but I think that would return rows where dFullText
has at least one instance of car
in it, or the equivalent of this sql:
所以包含类似于喜欢,但会计算字符串在文本字段中出现的次数。我无法使用包含在您发布的查询中使用它的方式找到资源,但我认为这将返回其中dFullText
至少有一个实例的行car
,或者与此 sql 等效的行:
Select * from blabla where dFullText like "%car%"
Hereis another source.
这是另一个来源。
回答by Padmarag
See this example from oracle.com
请参阅oracle.com 中的此示例
declare
rowno number := 0;
begin
for c1 in (SELECT SCORE(1) score, title FROM news
WHERE CONTAINS(text, 'oracle', 1) > 0
ORDER BY SCORE(1) DESC)
loop
rowno := rowno + 1;
dbms_output.put_line(c1.title||': '||c1.score);
exit when rowno = 10;
end loop;
end;