在使用mysql時候,某些字段會存儲中文字元,或是包含中文字元的串,查詢出來的方法是:
SELECT col FROM table WHERE length(col)!=char_length(col)
網上搜尋有很多種查詢方法,但是試了很多都不行,這個是找到的可以使用的查詢方法,原理其實很簡單,當字元集為UTF-8,并且字元為中文時,
length()
和
char_length()
兩個方法傳回的結果是不相同的。
# 以下這兩個方法查詢字段中是否包含中文
SELECT country FROM kaggle_main_info WHERE length(country)!=char_length(country);
select country from kaggle_main_info where not(country regexp "[\u0391-\uFFE5]") ORDER BY country DESC ;
SELECT col FROM table WHERE length(col)!=char_length(col)
length()
char_length()
# 以下這兩個方法查詢字段中是否包含中文
SELECT country FROM kaggle_main_info WHERE length(country)!=char_length(country);
select country from kaggle_main_info where not(country regexp "[\u0391-\uFFE5]") ORDER BY country DESC ;