简体   繁体   English

使用通配符的搜索功能

[英]Search functionality using wild card

I'm working on seach function where request is coming from front end with the wild card and based on the request it should output desired outcome.我正在研究 seach 函数,其中请求来自带有通配符的前端,并根据请求输出所需的结果。

Let's say we have a Name colum In DB with some records:假设我们在 DB 中有一个 Name 列,其中包含一些记录:

Name
---------
political party Delhi, IN (ruling)
political party Mumbai, IN (ruling)
political party Kerala, IN (not ruling)
political party Goa, IN (ruling)

 Now from JSP page request is coming as *Del*ruling* (or request could come just as *Del*) and outcome should be: political party Delhi, IN (ruling). I spent few days but could not find how to implement this functionality. Any guidance will be highly appreciated.

MySQL supports wildcards. MySQL 支持通配符。 They are denoted by the % character and used in a LIKE statement.它们由%字符表示并在LIKE语句中使用。 So just replace all '*' with '%' and you're good to go!因此,只需将所有 '*' 替换为 '%' 就可以了!

SELECT *
FROM articles
WHERE body LIKE '%Del%ruling%'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM