OCTET_LENGTH() Function in MySQL

In this article, we are going to cover the OCTET_LENGTH function. And will see syntax and example of OCTET_LENGTH function. Let’s discuss one by one.

OCTET_LENGTH function in MySQL is used to returns the number of characters in a given string.

Syntax :

OCTET_LENGTH( str )

Parameter :
This function accepts one parameter as mentioned above in the syntax and described below in the example.

  • str : Given string whose number of characters is to be find.

Returns –
It returns the length of given string.
Example-1 :
Applying OCTET_LENGTH() Function to a string.



SELECT OCTET_LENGTH('geeksforgeeks') 
as String_Length;

Output :

String_Length
13

Example-2 :
Applying OCTET_LENGTH() Function to a number string.

SELECT OCTET_LENGTH(56432) 
as Length;

Output :

Length
5

Example-3 :
Applying OCTET_LENGTH() Function to a  column in a table.

Table – Student_Details

Student_IdStudent_Name
134500 Amit Singh
134501 Arunima Rao
134502 Shreya Sharma
134503 Leena Mondal

Finding total length of name of every student(includes one space).

SELECT OCTET_LENGTH(Student_Name) as Name_Length 
FROM Student_Details ;

Output :

Name_Length
10
11
13
12

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.