Sunday 18 December 2011

MySQL Length Function

You can use the length() function to see how long column values in a table are as follows:
 
mysql> insert into andrews_table values ('Joe');
Query OK, 1 row affected (0.00 sec)
 
mysql> insert into andrews_table values ('Fred');
Query OK, 1 row affected (0.00 sec)
 
mysql> insert into andrews_table values ('Brian');
Query OK, 1 row affected (0.00 sec)
 
mysql> insert into andrews_table values ('Andrew');
Query OK, 1 row affected (0.00 sec)
 
mysql> select col1, length(col1) from andrews_table;
+--------+--------------+
| col1   | length(col1) |
+--------+--------------+
| Andrew |            6 |
| Brian  |            5 |
| Fred   |            4 |
| Joe    |            3 |
+--------+--------------+
4 rows in set (0.00 sec)
 
mysql>

No comments: