Skip to content
Related Articles

Related Articles

CHARACTER_LENGTH() Function in MySQL
  • Last Updated : 03 Dec, 2020

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 :

LenOfStr
13

Example-2 :
Using CHARACTER_LENGTH() function to calculate the length of a given string as follows.

SELECT CHARACTER_LENGTH("//  GeeksforGeeks  //") 
AS LenOfStr

Output :

LenOfStr
21

Example-3 :
Using CHARACTER_LENGTH() function to calculate the length of every column in given table as follows.
Table — Cricketers_details :

PLAYER_IDPLAYER_NAMERUNS_SCORED
11Yuvraj Singh144000
41Dinesh Kartik100000
05Virat Kohli500000
99Chris Gale410000
07M.S Dhoni700000

Now, used the following command given below for calculating character length.

SELECT CHARACTER_LENGTH(PLAYER_NAME) AS LenOfCol  
FROM Cricketers_details;

Output :

LenOfCol

12

13



11

10

9

Example-4 :
Using CHARACTER_LENGTH() function to calculate the length of a given string as follows.

SELECT CHARACTER_LENGTH("//  @#$$#@  //") 
AS LenOfStr

Output :

LenOfStr

14

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :