CHAR_LENGTH() Function in MySQL
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 :
Example-2 : CHAR_LENGTH() function to find the length for a String.
SELECT CHAR_LENGTH("SQL Tutorial in geeksforgeeks") AS LengthOfString
Output :
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 :
Last Updated :
21 Jun, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...