如何查找存储在指定 MySQL 列中的文本大小?


你可以使用 MySQL 的 length() 来查找特定列中存储的文本的大小。让我们首先创建一个表

mysql> create table DemoTable
   (
   CustomerName longtext
   );
Query OK, 0 rows affected (0.67 sec)

使用 insert 命令在表中插入记录 -

mysql> insert into DemoTable values('Robert');
Query OK, 1 row affected (0.14 sec)

使用 select 语句显示表中的所有记录 -

mysql> select *from DemoTable;

这会生成以下输出 -

+--------------+
| CustomerName |
+--------------+
| Robert       |
+--------------+
1 row in set (0.00 sec)

这是查找存储在特定列中的文本大小的查询 -

mysql> select length(CustomerName) from DemoTable;

这会生成以下显示文本大小的输出 -

+----------------------+
| length(CustomerName) |
+----------------------+
| 6                    |
+----------------------+
1 row in set (0.01 sec)

更新于: 30-7-2019

213 次浏览

开启你的 职业生涯

通过完成课程获得认证

开始学习
广告
© . All rights reserved.