MySQL搜索忽略连字符 [英] MySQL search to ignore hyphens

查看:73
本文介绍了MySQL搜索忽略连字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在MySQL中通过"1800flowers"搜索"1-800-flowers"?

How can I search for "1-800-flowers" by "1800flowers" in MySQL?

我有数据"1-800-flowers",但我想按"1800flowers"找到它.

I have the data "1-800-flowers", but I want to find it by "1800flowers".

推荐答案

最好创建第二列,并用1800flowers填充(替换所有要忽略的字符)并进行搜索.这样,您就可以充分利用索引.

You're probably best off creating a second column that you fill with 1800flowers (replacing all characters you want to ignore) and searching that. That way, you can make full use of indexing.

一种快速转换所有现有数据的方法是

A quick way to convert all existing data would be

UPDATE table SET columnname_without_hyphens = REPLACE(columnname, "-", "");

这篇关于MySQL搜索忽略连字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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