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_Id | Student_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 |