如何在mysql中搜索精确的字符串

发布于 2024-11-19 02:49:22 字数 201 浏览 3 评论 0原文

我正在尝试在 mysql 中搜索字符串的精确匹配。该字符串是“nrew”。但是当我执行以下查询时,我仍然得到结果:

SELECT UserID FROM sys_users WHERE UserID='NREW'
SELECT UserID FROM sys_users WHERE UserID='NrEw'

请帮忙。

I'm trying to search for an exact match of a string in mysql. The string is 'nrew'. But when I do the queries below, I still get a result:

SELECT UserID FROM sys_users WHERE UserID='NREW'
SELECT UserID FROM sys_users WHERE UserID='NrEw'

Please help.

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

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

发布评论

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

评论(5

一抹淡然 2024-11-26 02:49:22
SELECT UserID FROM sys_users WHERE BINARY UserID='NREW'
SELECT UserID FROM sys_users WHERE BINARY UserID='NREW'
莫相离 2024-11-26 02:49:22

MySQL 用于进行比较的默认排序规则不区分大小写。您需要指定区分大小写的排序规则或二进制。您可以在创建列时或在查询中执行此操作。

例如:

SELECT UserID FROM sys_users WHERE UserID='NREW' COLLATE latin1_bin

正确的排序规则取决于您的字符集。对于默认的 latin1,您可以使用 latin1_bin。对于utf8utf8_bin

The default collation which MySQL uses to make comparisons is case insensitive. You need to specify a case sensitive collation or binary. You can either do this when creating the column, or in the query.

For example:

SELECT UserID FROM sys_users WHERE UserID='NREW' COLLATE latin1_bin

The proper collation depends on your character set. For latin1, the default, you can use latin1_bin. For utf8, utf8_bin.

ペ泪落弦音 2024-11-26 02:49:22

可以使用关键字Binary,

SELECT UserID FROM sys_users WHERE BINARY UserID='nrew'

参考这里

You can use keyword Binary,

SELECT UserID FROM sys_users WHERE BINARY UserID='nrew'

refer to here

智商已欠费 2024-11-26 02:49:22

一种方法是使用 LIKE BINARY 而不是 =

SELECT UserID FROM sys_users WHERE UserID LIKE BINARY 'nrew';

One method is to use LIKE BINARY instead of =:

SELECT UserID FROM sys_users WHERE UserID LIKE BINARY 'nrew';
晨曦慕雪 2024-11-26 02:49:22

尝试一下:http://www.devx.com/tips/Tip/13043

Select UserID from sys_users where convert(varbinary, UserID) = convert(varbinary, 'NREW') 

或者尝试 COLLATE

http://aspadvice.com/blogs/ssmith/archive/2007/09/30/Case-Sensitive-or-Insensitive-SQL-Query.aspx

Give this is try: http://www.devx.com/tips/Tip/13043

Select UserID from sys_users where convert(varbinary, UserID) = convert(varbinary, 'NREW') 

Or try COLLATE

http://aspadvice.com/blogs/ssmith/archive/2007/09/30/Case-Sensitive-or-Insensitive-SQL-Query.aspx

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