

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How can I use MySQL OCTET_LENGTH() function to count the number of characters stored in a 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)
- Related Questions & Answers
- How can we get some last number of characters from the data stored in a MySQL table’s column?
- How can we get some starting number of characters from the data stored in a MySQL table’s column?
- How can I use MySQL INTERVAL() function with a column of a table?
- How can I use SPACE() function along with MySQL’s column data?
- How can I write a MySQL stored function that calculates the factorial of a given number?
- How can I count the number of days in MySQL?
- What is MySQL OCTET_LENGTH() function?
- How can we use a MySQL stored function in a database query?
- How to repeat the values stored in a data column of MySQL table?
- Can I get the count of repeated values in a column with MySQL?
- How can I use IFNULL() function at the place of COALESCE() function in MySQL?
- How can we use MySQL POWER() function with the column’s data values?
- How can we use MySQL EXPORT_SET() function with column of a table?
- How can I count unique records from a column in MySQL database?
- How can we alter a MySQL stored function?
Advertisements