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