The CHARACTER_LENGTH() function returns the number of characters in a string. It is equal to CHAR_LENGTH().
MySQL CHARACTER_LENGTH Function Syntax
SQL
x
1
CHARACTER_LENGTH(string);
MySQL CHARACTER_LENGTH Function Example
This query returns the number of characters in the string 'SQL Tutorial'
.
SQL
1
1
SELECT CHARACTER_LENGTH('SQL Tutorial') AS LengthOfString;
Note: The CHARACTER_LENGTH() function is supported in MySQL but not in SQLite. This example does not work in the TechKubo playground.
MySQL CHARACTER_LENGTH Function Parameters
Parameter | Description |
---|---|
string | The string to count the number of characters. Required. |
MySQL CHARACTER_LENGTH Function Table Column Example
This query returns the number of characters in the first_name column for each patient.
SQL
1
1
SELECT CHARACTER_LENGTH(first_name) AS LengthOfName
2
FROM Patients;
Note: The CHARACTER_LENGTH() function is supported in MySQL but not in SQLite. This example does not work in the TechKubo playground.
MySQL CHARACTER_LENGTH Function Notes
- The result is the number of characters, not bytes.
CHARACTER_LENGTH()
is equivalent toCHAR_LENGTH()
.- Works in MySQL 4.0 and higher.