mysql喜欢语句而不是默认情况下对病例不敏感的语句

发布于 2025-02-06 15:24:38 字数 451 浏览 1 评论 0原文

据我所知,就像MySQL中的语句一样,默认情况下对案例不敏感此处显示

就我而言,例如,他们似乎不是,例如select *从concat(名称,',姓氏)的用户中选择 *,例如'%rob%'不返回任何东西,而select *从concat(name,'',姓氏)的用户中,例如'%rob%'返回其“名称”列为“ Robert”的记录。

我想要从用户中选择 * concat(name,'',姓氏),例如'%rob%'才能返回其“名称”列为“ Robert”的记录。

As far as I know, LIKE statements in MySQL are case-insensitive by default as shown here.

In my case, it seems they are not, for instance SELECT * FROM users WHERE CONCAT(name, ' ', surname) LIKE '%rob%' doesn't return anything, while SELECT * FROM users WHERE CONCAT(name, ' ', surname) LIKE '%Rob%' returns a record whose "name" column is "Robert".

I want SELECT * FROM users WHERE CONCAT(name, ' ', surname) LIKE '%rob%' to return the record whose "name" column is "Robert".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独留℉清风醉 2025-02-13 15:24:38
SELECT * FROM users WHERE LOWER(CONCAT(name, ' ', surname)) LIKE '%rob%'
SELECT * FROM users WHERE LOWER(CONCAT(name, ' ', surname)) LIKE '%rob%'
酒废 2025-02-13 15:24:38

据我所知,就像MySQL中的语句默认情况下对细节不敏感。

本文中描述的信息不正确。字符串操作中的情况敏感性取决于整理。

mysql 8.0参考手册/角色集,collat​​ions,collat​​ions,collat​​ions,unicode


txt_as_cs varchar(255)caltate utf8mb4_0900_as_cs);
插入测试值
('绿色','绿色),
('绿色','绿色),
('绿色','绿色');

 选择txt_ai_ci, 
       txt_ai_ci喜欢'gr%', 
       txt_as_cs, 
       txt_as_cs,例如'gr%', 
       txt_as_cs整理UTF8MB4_0900_AI_CI喜欢'gr%'
从测试
 
txt_ai_citxt_ai_ci喜欢'gr%'txt_as_cstxt_as_cs,例如'gr%'txt_as_cs comalate utf8mb4_0900_ai_ai_ci喜欢'gr%'
绿色1绿色01
绿色1绿色11
绿色1绿色01

1 green 1 em> db< https://dbfiddle.uk/?rdbms=mysql_8.0& fiddle=3cdb69bf824d9f20373666f813cbbbb75b8“ rel =“ nofollow noreferrer”>在这里

As far as I know, LIKE statements in MySQL are case-insensitive by default as shown here.

The information described in this article is not correct. The case sensitivity in string operations depends on the collation.

MySQL 8.0 Reference Manual / Character Sets, Collations, Unicode.

CREATE TABLE test (txt_ai_ci VARCHAR(255) COLLATE utf8mb4_0900_ai_ci,
                   txt_as_cs VARCHAR(255) COLLATE utf8mb4_0900_as_cs);
INSERT INTO test VALUES
('GREEN', 'GREEN'),
('Green', 'Green'),
('green', 'green');
SELECT txt_ai_ci, 
       txt_ai_ci LIKE 'Gr%', 
       txt_as_cs, 
       txt_as_cs LIKE 'Gr%', 
       txt_as_cs COLLATE utf8mb4_0900_ai_ci LIKE 'Gr%'
FROM test
txt_ai_citxt_ai_ci LIKE 'Gr%'txt_as_cstxt_as_cs LIKE 'Gr%'txt_as_cs COLLATE utf8mb4_0900_ai_ci LIKE 'Gr%'
GREEN1GREEN01
Green1Green11
green1green01

db<>fiddle here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文