CHARACTER_LENGTH() Function in MySQL
CHARACTER_LENGTH() :
This function in MySQL helps to find the length of given string. The length is measured in form of characters. Moreover, CHARACTER_LENGTH() is also the synonym of CHAR_LENGTH() function.
Syntax :
CHARACTER_LENGTH(string)
Parameter :
The function accepts only one parameter as follows.
- string –
A string whose length to be found.
Returns :
It will return the length of given string.
Example-1 :
Using CHARACTER_LENGTH() function to calculate the length of a given string as follows.
SELECT CHARACTER_LENGTH("GeeksforGeeks") AS LenOfStr
Output :
Example-2 :
Using CHARACTER_LENGTH() function to calculate the length of a given string as follows.
SELECT CHARACTER_LENGTH("// GeeksforGeeks //")
AS LenOfStr
Output :
Example-3 :
Using CHARACTER_LENGTH() function to calculate the length of every column in given table as follows.
Table — Cricketers_details :
PLAYER_ID |
PLAYER_NAME |
RUNS_SCORED |
11 |
Yuvraj Singh |
144000 |
41 |
Dinesh Kartik |
100000 |
05 |
Virat Kohli |
500000 |
99 |
Chris Gale |
410000 |
07 |
M.S Dhoni |
700000 |
Now, used the following command given below for calculating character length.
SELECT CHARACTER_LENGTH(PLAYER_NAME) AS LenOfCol
FROM Cricketers_details;
Output :
Example-4 :
Using CHARACTER_LENGTH() function to calculate the length of a given string as follows.
SELECT CHARACTER_LENGTH("// @#$$#@ //")
AS LenOfStr
Output :
Last Updated :
03 Dec, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...