Find size of text stored in a specific MySQL column?


You can use length() from MySQL to find the size of text stores in a specific column. Let us first create a table

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

Insert records in the table using insert command −

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

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output−

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

Here is the query to find the size of text stored in a specific column −

mysql> select length(CustomerName) from DemoTable;

This will produce the following output displaying the size of text −

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

Updated on: 30-Jul-2019

197 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements