search
HomeDatabaseMysql Tutorialsql模糊搜索有通配符怎么操作

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

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

例:

 代码如下 复制代码

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
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
oracle通配符有哪些oracle通配符有哪些Nov 08, 2023 am 10:02 AM

oracle通配符有“%”、“_”、“[]”和“[^]"。详细介绍:1、通配符"%"表示匹配任意字符,包括零个字符,在Oracle中使用通配符"%"可以实现模糊查询,当在查询语句中使用通配符"%"时,查询将返回所有与指定模式匹配的字符串;2、通配符"_"表示匹配任意单个字符,在Oracle中使用通配符"_"可以实现精确匹配,当在查询语句中使用通配符等等。

如何在php中使用高德地图API实现地点名称的模糊搜索如何在php中使用高德地图API实现地点名称的模糊搜索Jul 31, 2023 pm 02:13 PM

如何在PHP中使用高德地图API实现地点名称的模糊搜索概述:在开发一个基于地理位置的应用时,有时候需要根据用户输入的地点名称进行模糊搜索,并返回搜索结果。高德地图提供了一套丰富的API,可以轻松实现这一功能。本文将介绍如何在PHP中使用高德地图API实现地点名称的模糊搜索,并为您提供代码示例。步骤:获取高德地图API的开发者密钥首先,您需要在高德地图开放平台

正则表达式通配符有哪些正则表达式通配符有哪些Nov 17, 2023 pm 01:40 PM

正则表达式通配符有"."、"*"、"+"、"?"、"^"、"$"、"[]"、"[^]"、"[a-z]"、"[A-Z]"、"[0-9]"、"\d"、"\D"、"\w"、"\W"、"\s&quo

在查找文件时,通配符*与?的含义是什么在查找文件时,通配符*与?的含义是什么Jul 25, 2022 am 11:43 AM

通配符“*”可以代表任何字符串,能匹配零个、单个或多个字符;而通配符“?”仅代表单个字符串,且此单字必须存在。通配符是一种特殊语句,主要有星号“*”和问号“?”,用来模糊搜索文件;“*”匹配的数量不受限制,而“?”的匹配字符数则受到限制。当查找文件夹时,可以使用它来代替一个或多个真正字符;当不知道真正字符或者懒得输入完整名字时,常常使用通配符代替一个或多个真正的字符。

word通配符有哪些word通配符有哪些Jan 22, 2024 pm 04:03 PM

word通配符有“?”、“*”、“[]”、“!”、“%”等。详细介绍:1、问号(?):表示匹配任意单个字符。例如,“c?t”可以匹配“cat”、“cut”等单词;2、星号(*):表示匹配零个或多个字符。例如,“colr”可以匹配“color”、“colour”等单词;3、方括号([]):表示匹配方括号内任意一个字符。例如,“[aeiou]”可以匹配任意一个元音字母;4、感叹号等

如何使用Java代码在百度地图上实现地点的模糊搜索?如何使用Java代码在百度地图上实现地点的模糊搜索?Jul 30, 2023 pm 11:31 PM

如何使用Java代码在百度地图上实现地点的模糊搜索?随着互联网的发展,人们对于地理位置信息的需求也越来越高。比如,我们可能需要通过关键字来搜索附近的餐馆、酒店或者其他特定的地点。百度地图提供了丰富的地点搜索功能,而使用Java代码结合百度地图API可以很方便地实现地点的模糊搜索。下面我们将介绍如何使用Java代码在百度地图上实现地点的模糊搜索。首先,我们需要

通配符*和?的区别是什么通配符*和?的区别是什么Aug 11, 2023 pm 01:20 PM

通配符*和?在使用方法和匹配范围上有一些区别。具体区别:1、在匹配范围上,通配符*可以匹配任意长度的字符序列,包括字母、数字、标点符号和空格等,通配符?只能匹配一个字符;2、在使用方法上,通配符*用于模糊匹配,可以匹配多个字符或字符序列,通配符?用于精确匹配,只能匹配一个字符。

Java 函数中的泛型通配符:上限和下限Java 函数中的泛型通配符:上限和下限Apr 25, 2024 pm 04:18 PM

在Java中,泛型通配符允许表示泛型类型,而不指定具体类型。上限通配符(

See all articles

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

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function