Mysql像包含wildcart一样提供了意外的结果 [英] Mysql Like containing wildcart giving unexpected result

查看:70
本文介绍了Mysql像包含wildcart一样提供了意外的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个非常简单的MySQL数据库表中有一个varchar列,该表包含2种不同类型的产品引用:

I have a varchar column inside a very simple MySQL Database table that contains 2 different types of product references :

一个像:14521_451_288,另一个像45742154

one like : 14521_451_288, and the others like 45742154

为了能够管理它们,我正在使用以下代码:

to be able to manage them, I'm using the following code :

WHERE ref LIKE '%_%'

但是会返回所有结果,即使没有下划线的引用也是如此.我在这里缺少基本的东西吗?

But all the results are returned, even the references without underscore. Am I missing something basic here?

推荐答案

_代表LIKE表达式中的任何一个字符.这就是为什么您返回所有值的原因.您需要转义_字符.

_ stand for any one character in a LIKE expression. That's why you return all values. You need to escape the _ character.

尝试一下:

WHERE ref LIKE '%\_%';

参考:

MySQL参考手册上的字符串文字

相关的SO问题

这篇关于Mysql像包含wildcart一样提供了意外的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆