Mysql Length Function

MySQL: LENGTH Function

This tutorial explains how to use the MySQL LENGTH function with syntax and examples.

Description

The MySQL LENGTH function returns the length of the specified string (measured in bytes).

Syntax

The syntax for the LENGTH function in MySQL is:

LENGTH( string )

Parameters or Arguments

string

The string to return the length for.

Note

  • When using the LENGTH function, a multi-byte character is counted as more than one byte.
  • See also the CHAR_LENGTH function.

Applies To

The LENGTH function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

Let's look at some MySQL LENGTH function examples and explore how to use the LENGTH function in MySQL.

For example:

mysql> SELECT LENGTH(NULL);
Output: NULL

mysql> SELECT LENGTH('');
Output: 0

mysql> SELECT LENGTH(' ');
Output: 1


mysql> SELECT LENGTH('AODBA.com');
Output: 9