如何在 MySQL 中找到非 ASCII 字符?

How can I find non-ASCII characters in MySQL?(如何在 MySQL 中找到非 ASCII 字符?)

本文介绍了如何在 MySQL 中找到非 ASCII 字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个 MySQL 数据库,该数据库有一些从 Excel 导入的数据.数据包含非ASCII 字符(破折号等)以及隐藏的回车或换行.有没有办法使用 MySQL 找到这些记录?

I'm working with a MySQL database that has some data imported from Excel. The data contains non-ASCII characters (em dashes, etc.) as well as hidden carriage returns or line feeds. Is there a way to find these records using MySQL?

推荐答案

这完全取决于您定义的ASCII",但我建议尝试这样的查询变体:

It depends exactly what you're defining as "ASCII", but I would suggest trying a variant of a query like this:

SELECT * FROM tableName WHERE columnToCheck NOT REGEXP '[A-Za-z0-9]';

该查询将返回 columnToCheck 包含任何非字母数字字符的所有行.如果您有其他可接受的字符,请将它们添加到正则表达式中的字符类中.例如,如果句号、逗号和连字符都可以,则将查询更改为:

That query will return all rows where columnToCheck contains any non-alphanumeric characters. If you have other characters that are acceptable, add them to the character class in the regular expression. For example, if periods, commas, and hyphens are OK, change the query to:

SELECT * FROM tableName WHERE columnToCheck NOT REGEXP '[A-Za-z0-9.,-]';

MySQL 文档最相关的页面可能是 12.5.2 正则表达式.

The most relevant page of the MySQL documentation is probably 12.5.2 Regular Expressions.

这篇关于如何在 MySQL 中找到非 ASCII 字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 MySQL 中找到非 ASCII 字符?