首页 > 数据库 > MySQL > MySQL两种识别是否有中文字符的方法
drop table t1;
create table t1 ( id varchar(200)) default charset=utf8 ;
insert into t1 values ('中文'),('sdalfkj');
1)用正式表达式 regexp "[u0391-uFFE5]"
root@127.0.0.1 : test 21:55:33> select id ,id regexp "[u0391-uFFE5][u0391-uFFE5]" from t1;
+---------+--------------------------------------------+
| id | id regexp "[u0391-uFFE5][u0391-uFFE5]" |
+---------+--------------------------------------------+
| 中文 | 0 |
| sdalfkj | 1 |
+---------+--------------------------------------------+
2 rows in set (0.01 sec)
2) 用length和char_length
root@127.0.0.1 : test 23:33:13> select id,length(id),char_length(id) from t1;
+---------+------------+-----------------+
| id | length(id) | char_length(id) |
+---------+------------+-----------------+
| 中文 | 6 | 2 |
| sdalfkj | 7 | 7 |
+---------+------------+-----------------+
2 rows in set (0.00 sec)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/703656/viewspace-1043366/ ,如需转载,请注明出处,否则将追究法律责任。