MySQL LENGTH Function with Examples

How to Use the MySQL LENGTH Function

In this tutorial, you'll learn how to use the MySQL LENGTH() function. LENGTH() is a function to return the length of a given string.

LENGTH Syntax

The syntax of the LENGTH() function is as follows:

LENGTH(string)

Examples

Example 1

The following statement returns the length of the string:

SELECT LENGTH("This site is one of the best SQL tutorials.");

Result:

43

Example 2

The following statement returns the length of the string:

SELECT LENGTH(" This site is one of the best SQL tutorials. ");

Result:

45

Note that a single space is considered as one character, and counted as one length.

In this tutorial, you've learned how to use the MySQL LENGTH() function. LENGHT() is a useful function that allows you to count the number of characters in a given string.


See also:
MySQL LIKE Operator Pattern Matching and Examples
MySQL SUBSTRING_INDEX Function with Examples
MySQL EXISTS Operator with Examples
MySQL ROW_NUMBER Function with Examples
MySQL CONCAT() Function | Concatenate Strings in MySQL

Leave a Comment