查询表中某个字段规定长度 查询表中手机号码为9位或者11位的(sj)请教,怎么在mysql中写查询语句了?select count(*) from table where sj='9' or sj='11'; ------------这里收集长度要用什么函数了?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select count(*) from table where char_length(sj)='9' or char_length(sj)='11'; mysql中查某个字段的长度 length: 是计算字段的长度一个汉字是算三个字符,一个数字或字母算一个字符char_length:不管汉字还是数字或者是字母都算是一个字符mysql> select char_length('士大夫健康');+---------------------------+| char_length('士大夫健康') |+---------------------------+| 10 |+---------------------------+1 row in set (0.00 sec)mysql> select length('士大夫健康');+----------------------+| length('士大夫健康') |+----------------------+| 10 |+----------------------+在这里为什么char_length 和 length 的值是一样了?? mysql> create table tb_len_a(a varchar(20)) default character set gbk;Query OK, 0 rows affected (0.01 sec)mysql> insert into tb_len_a values('我的') -> ;Query OK, 1 row affected (0.00 sec)mysql> select a,length(a) from tb_len_a;+------+-----------+| a | length(a) |+------+-----------+| 我的 | 4 | +------+-----------+1 row in set (0.01 sec)mysql> select a,char_length(a) from tb_len_a;+------+----------------+| a | char_length(a) |+------+----------------+| 我的 | 2 | +------+----------------+1 row in set (0.01 sec)mysql> oh,只有数据库本身存在才能查~~~ 字符集的问题。mysql> select length('我的'),char_length('我的');+----------------+---------------------+| length('我的') | char_length('我的') |+----------------+---------------------+| 4 | 4 |+----------------+---------------------+1 row in set (0.00 sec)mysql> set names 'gb2312';Query OK, 0 rows affected (0.00 sec)mysql> select length('我的'),char_length('我的');+----------------+---------------------+| length('我的') | char_length('我的') |+----------------+---------------------+| 4 | 2 |+----------------+---------------------+1 row in set (0.06 sec)mysql> 关于LINUX MYSQL的入门级问题 mysql command line client 怎样输入中文 replace into不支持一个参照表的 插入或更新 expire_logs_days 参数疑问? web项目中对mysql服务监控问题 表性能问题 我想要mysql 4.0 manual即官方网站在线那份 怎样实现对字段使用函数查询 MySQL中group by的问题 阿里云服务器 mysql5.6版本更新报错 遇到一个问题,不知道是不是mysql的bug 在Mysql中如何查询含有某项值的所有表名
length: 是计算字段的长度一个汉字是算三个字符,一个数字或字母算一个字符char_length:不管汉字还是数字或者是字母都算是一个字符
mysql> select char_length('士大夫健康');
+---------------------------+
| char_length('士大夫健康') |
+---------------------------+
| 10 |
+---------------------------+
1 row in set (0.00 sec)mysql> select length('士大夫健康');
+----------------------+
| length('士大夫健康') |
+----------------------+
| 10 |
+----------------------+
在这里为什么char_length 和 length 的值是一样了??
Query OK, 0 rows affected (0.01 sec)mysql> insert into tb_len_a values('我的')
-> ;
Query OK, 1 row affected (0.00 sec)mysql> select a,length(a) from tb_len_a;
+------+-----------+
| a | length(a) |
+------+-----------+
| 我的 | 4 |
+------+-----------+
1 row in set (0.01 sec)mysql> select a,char_length(a) from tb_len_a;
+------+----------------+
| a | char_length(a) |
+------+----------------+
| 我的 | 2 |
+------+----------------+
1 row in set (0.01 sec)mysql>
+----------------+---------------------+
| length('我的') | char_length('我的') |
+----------------+---------------------+
| 4 | 4 |
+----------------+---------------------+
1 row in set (0.00 sec)mysql> set names 'gb2312';
Query OK, 0 rows affected (0.00 sec)mysql> select length('我的'),char_length('我的');
+----------------+---------------------+
| length('我的') | char_length('我的') |
+----------------+---------------------+
| 4 | 2 |
+----------------+---------------------+
1 row in set (0.06 sec)mysql>