ใช้ LENGTH() เพื่อนับจำนวนไบต์ของข้อความในคอลัมน์
ตัวอย่าง
mysql> create table DemoTable ( CustomerName longtext ); Query OK, 0 rows affected (0.67 sec)
mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.14 sec)
ข้อมูล
mysql> select * from DemoTable;
+--------------+ | CustomerName | +--------------+ | Robert | +--------------+
หาความยาว
mysql> select length(CustomerName) from DemoTable;
+----------------------+ | length(CustomerName) | +----------------------+ | 6 | +----------------------+
หมายเหตุ: LENGTH() นับไบต์ สำหรับ UTF-8 ตัวอักษรไทย 1 ตัว = 3 ไบต์ ใช้ CHAR_LENGTH() หากต้องการนับจำนวนตัวอักษร