开发者

How to check if a row in a table has muti-byte characters in it in a MySQL database?

开发者 https://www.devze.com 2023-04-08 23:22 出处:网络
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 c开发者_如何转开

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 c开发者_如何转开发haracters. How can I query the tables using MySQL functions to determine which rows have multi-byte characters. I am using MySQL version 5.1


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号