简体   繁体   English

MYSQL,忽略空格,标点符号,查询中的重音符号

[英]MYSQL, ignore whitespace, punctuation, substitute accents in query

I need a way to use my dictionary with province abbreviations, full names and territories without having to add an entry for every possible misspelling of Ontario. 我需要一种方法来将我的词典与省的缩写,全名和地区一起使用,而不必为任何可能的安大略拼写错误添加条目。 Table is as such: 表是这样的:

state       |name     | territory
===================================
AB           Alberta   West

Data is as such: 数据是这样的:

"Ontario,"
"ON,"
"ON"
"On"
" Ontario"
"Ontario "
" Ontario "


Quebec
Québec
QU
QB
Quebec,

Just an idea, knowing it can't be used for all your db. 只是一个想法,知道它不能用于您的所有数据库。
Anyway: what about using 无论如何:如何使用
SELECT * FROM table WHERE name LIKE '%ontario%' ? SELECT * FROM table WHERE name LIKE '%ontario%'吗?

not a real answer for you immediate problem, but this is what normalization is for. 对于您眼前的问题,这不是一个真正的答案,但这就是规范化的目的。 make another table for provinces, and then link that to the original table instead of allowing freeform text. 为省份创建另一个表,然后将其链接到原始表,而不允许使用自由格式的文本。

alterantely, add a trigger tot he input to enforce some consistency to the data collected. 或者,在输入中添加一个触发器,以使收集到的数据具有一定的一致性。 (at least trim the spaces, make it all UPPER, maybe check for valid entries.. etc.) (至少修剪空格,使其全部变大,也许检查有效条目。。等)

A bit late for the OP, but for others trying to do loose match searches, check out STRCMP() and SOUNDEX() as detailed here: 对于OP来说有点晚了,但是对于其他尝试进行松散匹配搜索的人,请查看STRCMP()和SOUNDEX(),如下所示:

http://www.madirish.net/node/85 http://www.madirish.net/node/85

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM