MySQL 中查询结果少于 X 个字符?
mysqlmysqli database更新于 2024/8/14 19:24:17
您可以将 CHAR_LENGTH() 与 WHERE 子句一起使用。让我们首先创建一个表 −
mysql> create table DemoTable -> ( -> FullName varchar(50) -> ); Query OK, 0 rows affected (1.75 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values('Chris Brown');
Query OK, 1 row affected (0.40 sec)
mysql> insert into DemoTable values('David Miller');
Query OK, 1 row affected (0.91 sec)
mysql> insert into DemoTable values('Robert Miller');
Query OK, 1 row affected (0.26 sec)
mysql> insert into DemoTable values('John Smith');
Query OK, 1 row affected (0.89 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
这将产生以下输出 −
+---------------+ | FullName | +---------------+ | Chris Brown | | David Miller | | Robert Miller | | John Smith | +---------------+ 4 rows in set (0.00 sec)
以下是在 MySQL 中获取少于 X 个字符的记录的查询−
mysql> select *from DemoTable where char_length(FullName) < 12;
这将产生以下输出 −
+-------------+ | FullName | +-------------+ | Chris Brown | | John Smith | +-------------+ 2 rows in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

