
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL OCTET_LENGTH Function to Count Characters in Data Column
We need to pass the column name as the argument of OCTET_LENGTH() function to count the number of characters stored in a data column. It displays the number of characters when referenced in SELECT clause. It can also be used as comparison value to decide whether or not the row should returned by using it in WHERE clause. The contents of ‘Student’ table are used to demonstrate it −
mysql> Select Name, OCTET_LENGTH(Name)As 'Str_Length' from Student; +---------+------------+ | Name | Str_Length | +---------+------------+ | Gaurav | 6 | | Aarav | 5 | | Harshit | 7 | | Gaurav | 6 | | Yashraj | 7 | +---------+------------+ 5 rows in set (0.00 sec) mysql> Select Name, OCTET_LENGTH(Name)As 'Str_Length' from Student Where OCTET_LENGTH(Name) < 7; +--------+------------+ | Name | Str_Length | +--------+------------+ | Gaurav | 6 | | Aarav | 5 | | Gaurav | 6 | +--------+------------+ 3 rows in set (0.06 sec)
Advertisements