如何查詢儲存在指定 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.