如何检查MySQL数据库中表中的行是否包含多字节字符?

发布于 2024-12-07 05:43:46 字数 146 浏览 2 评论 0原文

我有一个表,其中包含存储字符串值的 descr 列。 descr 中的某些值包含多字节字符,我想知道所有这些行,以便删除这些字符。如何使用 MySQL 函数查询表以确定哪些行具有多字节字符。我使用的是 MySQL 5.1 版本

I have a table which has column of descr which stores string values. Some of the values in descr has multi-byte characters in it and I want to know all those rows so I can remove those characters. How can I query the tables using MySQL functions to determine which rows have multi-byte characters. I am using MySQL version 5.1

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

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

发布评论

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

评论(2

不必了 2024-12-14 05:43:46
SELECT ...
FROM yourtable
WHERE CHAR_LENGTH(descr) <> LENGTH(descr)

char_length 是多字节感知的并返回实际的字符数。 Length() 是纯字节计数,因此 3 字节字符返回 3。

SELECT ...
FROM yourtable
WHERE CHAR_LENGTH(descr) <> LENGTH(descr)

char_length is multi-byte aware and returns the actual character count. Length() is a pure byte-count, so a 3-byte char returns 3.

芯好空 2024-12-14 05:43:46

您是否在 descr 列上尝试过排序规则和 CHARSET 函数?

您可以在这里找到该功能的描述:
http://dev.mysql.com/doc/refman/5.1 /en/information-functions.html

我认为根据您的需要,它更适合 COERCIBILITY 函数。您可以执行以下操作:

 select COERCIBILITY(descr, COLLATE utf8) from myTable; 

如果此函数返回 0,那么您必须编辑该行。

have you tried the collation and CHARSET functions on your descr column?

You can find the description of this functions here:
http://dev.mysql.com/doc/refman/5.1/en/information-functions.html

I think for your need it fits better the COERCIBILITY function. You can do something like:

 select COERCIBILITY(descr, COLLATE utf8) from myTable; 

and if this function returns 0 then you must edit the line.

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