Home Database Mysql Tutorial sql模糊搜索有通配符怎么操作

sql模糊搜索有通配符怎么操作

Jun 07, 2016 pm 05:49 PM
fuzzy search Wildcard

我们经常会碰到在数据库中使用模糊搜索时但是要查找的字符串中就会我们常用的通配符,这种情况要怎么处理呢,下面来看看。

如我要查找文章中的一个字符

例:

 代码如下 复制代码

select * from table where content like '%key%'

但是key中本身就有'%'号,这样肯定是sql语句出错了或查不出我们想要的内容。
 
后来百度找到了sql中ESCAPE定义转义符,这样就可以解决这个问题了。

示例:

 代码如下 复制代码

select * from table where content like '%/%%' escape '/'

/为转义字符,第二个%为普通字符,第一、三个%为通配符。
 

 代码如下 复制代码
select * from table where content like '%/%//%' escape '/'

/为转义字符,第二个%为普通字符,第一、三个%为通配符,第二个/为转义字符,第三个/为普通字符。

小提示

由于%是特殊字符,所以like后面的字符串中%需要转义,这是需要使用escape来定义转移符。例子中“”被定义为转

移字符。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the oracle wildcards? What are the oracle wildcards? Nov 08, 2023 am 10:02 AM

Oracle wildcard characters include "%", "_", "[]" and "[^]". Detailed introduction: 1. The wildcard character "%" means matching any character, including zero characters. Using the wildcard character "%" in Oracle can implement fuzzy query. When the wildcard character "%" is used in the query statement, the query will return all characters matching the specified character. Pattern matching string; 2. The wildcard character "_" means matching any single character. In Oracle, the wildcard character "_" can be used to achieve exact matching. When using wildcard characters in query statements, etc.

What are the regular expression wildcards? What are the regular expression wildcards? Nov 17, 2023 pm 01:40 PM

Regular expression wildcards include ".", "*", "+", "?", "^", "$", "[]", "[^]", "[a-z]", "[A-Z] ","[0-9]","\d","\D","\w","\W","\s&quo

How to use Amap API in php to implement fuzzy search of place names How to use Amap API in php to implement fuzzy search of place names Jul 31, 2023 pm 02:13 PM

Overview of how to use the Amap API in PHP to implement fuzzy search of place names: When developing an application based on geographical location, sometimes it is necessary to perform a fuzzy search based on the place name entered by the user and return the search results. Amap provides a rich set of APIs that can easily implement this function. This article will introduce how to use the Amap API in PHP to implement fuzzy search of place names and provide you with code examples. Steps: Obtain the developer key of the Amap API. First, you need to open the Amap open platform

What are the wildcard characters in word? What are the wildcard characters in word? Jan 22, 2024 pm 04:03 PM

Word wildcard characters include "?", "*", "[]", "!", "%", etc. Detailed introduction: 1. Question mark (?): indicates matching any single character. For example, "c?t" can match words such as "cat" and "cut"; 2. Asterisk (*): indicates matching zero or more characters. For example, "colr" can match words such as "color" and "colour"; 3. Square brackets ([]): means matching any character within the square brackets. For example, "[aeiou]" can match any vowel; 4. exclamation point, etc.

What do the wildcard characters * and ? mean when searching for files? What do the wildcard characters * and ? mean when searching for files? Jul 25, 2022 am 11:43 AM

The wildcard character "*" can represent any string and can match zero, single or multiple characters; while the wildcard character "?" only represents a single string, and this word must exist. Wildcard is a special statement, mainly including asterisk "*" and question mark "?", used to fuzzy search files; the number of matches for "*" is not limited, while the number of matching characters for "?" is limited. When looking for a folder, you can use it to replace one or more real characters; when you don't know the real characters or you are too lazy to enter the full name, you often use wildcards to replace one or more real characters.

How to use Java code to implement fuzzy search for locations on Baidu Maps? How to use Java code to implement fuzzy search for locations on Baidu Maps? Jul 30, 2023 pm 11:31 PM

How to use Java code to implement fuzzy search for locations on Baidu Maps? With the development of the Internet, people's demand for geographical location information is also getting higher and higher. For example, we may need to search for nearby restaurants, hotels or other specific places by keywords. Baidu Maps provides rich location search functions, and using Java code combined with Baidu Map API can easily implement fuzzy search for locations. Below we will introduce how to use Java code to implement fuzzy search for locations on Baidu Maps. First, we need

Generic wildcards in Java functions: upper and lower bounds Generic wildcards in Java functions: upper and lower bounds Apr 25, 2024 pm 04:18 PM

In Java, generic wildcards allow generic types to be represented without specifying concrete types. Upper limit wildcard (

What is the difference between wildcard characters * and ? What is the difference between wildcard characters * and ? Aug 11, 2023 pm 01:20 PM

The wildcards * and ? have some differences in usage and matching range. Specific differences: 1. In terms of matching range, the wildcard * can match any length of character sequence, including letters, numbers, punctuation marks, spaces, etc., while the wildcard ? can only match one character; 2. In terms of usage, the wildcard * is used Fuzzy matching can match multiple characters or character sequences. The wildcard character ? is used for exact matching and can only match one character.

See all articles