使用 包含如何搜索多个值
这就是我想做的:
select * from Person where CONTAINS((fName,sName),'John AND Doe')
所以我试图搜索 John Doe,但我发现我不能在这里使用 AND (只是显示我的思路)那么我如何在 fName 中搜索 John 并在 sName 中搜索 Doe ?但我不想像这样使用“包含”两次:
SELECT * FROM Person
WHERE CONTAINS((fName), 'John')
AND CONTAINS((sName), 'Doe');
因为我们可以有
(fName,sName)
但我不能使用
“约翰”、“多伊”/“约翰”和“多伊”
Here is what I am trying to do:
select * from Person where CONTAINS((fName,sName),'John AND Doe')
So I am trying to search for John Doe but I get that I cannot use AND here (just showing my chain of thought) so how can I search for John in the fName and Doe in the sName ? But I don't want to use "Contains" twice like this:
SELECT * FROM Person
WHERE CONTAINS((fName), 'John')
AND CONTAINS((sName), 'Doe');
Since we can have
(fName,sName)
but I cannot use
'John','Doe'/'John' AND 'Doe'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的语句
无法编译,因为 CONTAINS 返回一个数字,而不是布尔值。
在oracle上,它应该响应这种错误
(关系运算符错误的原因不是
AND
的存在,而是因为你尝试AND
两个数字)什么你打算做什么?如果要选择 person 表中
fName
列包含子字符串John
且sName
列包含子字符串Doe 的行
,您可以使用like
运算符,它使用%
作为通配符。我不太练习 CONTAINS 方法,但如果您想使用它,根据文档,您应该使用类似的内容
如果您真的不想使用
AND
运算符(对于任何晦涩难懂的内容)原因(例如证明 sql 注入过滤器不好),您可以使用此技巧:比较 2 列和like
运算符的串联,如下所示,但最后一个技巧也将匹配
所在的行fname
是John Doe
和sName
是Jean-Michel
:)Your statement
can't compile because CONTAINS returns a number, not a boolean.
It shall respond,on oracle, with this kind of error
(the relational operator error's cause is not the
AND
's existence, it's because you try toAND
two numbers)What do you intend to do? If you want to select the line in the person table whose
fName
columns contains the substringJohn
and whosesName
column contains the substringDoe
, you may use thelike
operator, which uses%
as a wildcard.I don't practice much the CONTAINS method, but if you desire to use it, according to documentation, you should use something like
If you really don't want to use the
AND
operator (for whatever obscure reason like proving a sql injection filter is bad), you can use this trick : compare a concatenation of the 2 columns and thelike
operator like sobut this last trick will also match the line where
fname
isJohn Doe
andsName
isJean-Michel
:)这应该有效:
但在您的情况下,您不想使用 2 contains so:
或者,您可以添加一个带有全文索引的新计算列。
添加这样的列:
并创建全文索引:
然后您可以执行以下操作:
希望它有效。
This should work:
But in your case you dont want to use 2 contains so:
Alternatively, you could add a new computed column with a full text index on it.
Add a column like this:
And create the full text index:
Then you can do this:
Hope it works.