CHAR_LENGTH() function in MySQL is used to find the length of a given string (in characters). It counts the number of characters and ignore whether the character(s) are single-byte or multi-byte.
Syntax :
CHAR_LENGTH(str)
Parameter : This method accepts one parameter as mentioned above and described below :
- str : A string whose length to be calculated.
Returns : It returns the length of a given string.
Example-1 : CHAR_LENGTH() function to find the length for a String.
SELECT CHAR_LENGTH("geeksforgeeks") AS LengthOfString
Output :
| LengthOfString |
|---|
| 13 |
Example-2 : CHAR_LENGTH() function to find the length for a String.
SELECT CHAR_LENGTH("SQL Tutorial in geeksforgeeks") AS LengthOfString
Output :
| LengthOfString |
|---|
| 29 |
Example-3 : CHAR_LENGTH() function to find the length for every String in a column of a Table.
Table - Student_Details :
| Student_Roll | Student_Name | Total_Marks |
|---|---|---|
| 1 | Amit | 450 |
| 2 | Aniket | 470 |
| 3 | Sanjana | 432 |
| 4 | Nirmal | 475 |
SELECT CHAR_LENGTH(Student_Name) AS LengthOfName FROM Student_Details;
Output :
| LengthOfName |
|---|
| 4 |
| 6 |
| 7 |
| 6 |