sql 通配符小问题 在线急等
本人mysql菜鸟一枚
遇到通配符的问题求助各位大神
我想选取users表中姓名包含"szo"或者"szö"的数据
所以写了以下代码:
select * from users where name like '%sz[oö]%'
数据库有这样的数据
但是返回值是0
尝试
select * from users where name like '%szo%' or name like '%szö%'
有结果
请问这两个有什么不一样?
回复讨论(解决方案)
mysql like 的通配符只有 "_" 和 "%"
"_"是匹配任意单个字符
"%"是匹配任意多个字符。
select * from users where name like '%sz[oö]%'
的意思就是 name 中包含 sz[oö] 的记录。
而不是 包含 szo 或 szö的记录
like并不是正则表达式匹配。而只是通配符%和_等匹配,因此并不支持[xy]这种字符组。
你可以尝试REGEXP
like并不是正则表达式匹配。而只是通配符%和_等匹配,因此并不支持[xy]这种字符组。
你可以尝试REGEXP
尝试过,一样的结果
有别的办法吗 ?
mysql like 的通配符只有 "_" 和 "%"
"_"是匹配任意单个字符
"%"是匹配任意多个字符。
select * from users where name like '%sz[oö]%'
的意思就是 name 中包含 sz[oö] 的记录。
而不是 包含 szo 或 szö的记录
明白了,有解决办法吗
select * from users where name like '%szo%' or name like '%szö%'
你不是已经用这个办法解决了吗?
like并不是正则表达式匹配。而只是通配符%和_等匹配,因此并不支持[xy]这种字符组。
你可以尝试REGEXP
尝试过,一样的结果
有别的办法吗 ?
不会吧?你的regexp是怎么写的?
select * from users where name regexp 'sz[oö]'
SELECT * FROM usersWHERE nameREGEXP '(a-z)*sz(o|ö)(a-z)*'LIMIT 0 , 30
解决了谢谢大家
结帖
like并不是正则表达式匹配。而只是通配符%和_等匹配,因此并不支持[xy]这种字符组。
你可以尝试REGEXP
尝试过,一样的结果
有别的办法吗 ?
不会吧?你的regexp是怎么写的?
select * from users where name regexp 'sz[oö]'
因为 like 不识别 [oö],regexp 不识别 %, 所以拉
SELECT * FROM usersWHERE nameREGEXP '(a-z)*sz(o|ö)(a-z)*'LIMIT 0 , 30
select * from users where name like '%szo%' or name like '%szoö%'
like并不是正则表达式匹配。而只是通配符%和_等匹配,因此并不支持[xy]这种字符组。
你可以尝试REGEXP
尝试过,一样的结果
有别的办法吗 ?
不会吧?你的regexp是怎么写的?
select * from users where name regexp 'sz[oö]'
尝试了一下你的代码 比我的简洁好用
谢谢 不嫌弃我这只菜鸟耐心解答
like并不是正则表达式匹配。而只是通配符%和_等匹配,因此并不支持[xy]这种字符组。
你可以尝试REGEXP
尝试过,一样的结果
有别的办法吗 ?
不会吧?你的regexp是怎么写的?
select * from users where name regexp 'sz[oö]'
因为 like 不识别 [oö],regexp 不识别 %, 所以拉
SELECT * FROM usersWHERE nameREGEXP '(a-z)*sz(o|ö)(a-z)*'LIMIT 0 , 30
既然用了regexp,你还要%有何用? 这就好比是穿着登山鞋去打篮球?
select * from users where name like '%szo%' or name like '%szö%'
你不是已经用这个办法解决了吗?
这个说来话长 , 还有 a ä i ï u ü 好麻烦
like并不是正则表达式匹配。而只是通配符%和_等匹配,因此并不支持[xy]这种字符组。
你可以尝试REGEXP
尝试过,一样的结果
有别的办法吗 ?
不会吧?你的regexp是怎么写的?
select * from users where name regexp 'sz[oö]'
尝试了一下你的代码 比我的简洁好用
谢谢 不嫌弃我这只菜鸟耐心解答
客气了。谁不是从菜鸟过来的。
掌握一定的技巧,往往能让学习效率加倍。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Alipay PHP...
