

- 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
Which function is a synonym of MySQL LENGTH() function?
As we know that, MySQL OCTET_LENGTH() function also measures the string length in ‘bytes’ hence, it is the synonym of MySQL LENGTH() function. The syntax of this function is OCTET_LENGTH(Str) where Str is a string whose length in characters has to be returned.
It is also not multi-byte safe like LENGTH() function. For example, if a string contains four 2-bytes characters then OCTET_LENGTH() function will return 8. It is demonstrated in the example below −
Example
mysql> Select OCTET_LENGTH('tutorialspoint'); +--------------------------------+ | OCTET_LENGTH('tutorialspoint') | +--------------------------------+ | 14 | +--------------------------------+ 1 row in set (0.00 sec)
The above result set shows that the length of string ‘tutorialspoint’ is 14 because it is yet not converted to Unicode character. The following query converts it into Unicode character −
mysql> SET @A = CONVERT('tutorialspoint' USING ucs2); Query OK, 0 rows affected (0.02 sec)
After converting the string in Unicode, it gives the result 28 instead of 14 because in Unicode a single character takes 2-bytes as shown below −
mysql> Select OCTET_LENGTH(@A); +------------------+ | OCTET_LENGTH(@A) | +------------------+ | 28 | +------------------+ 1 row in set (0.00 sec)
- Related Questions & Answers
- What is the purpose of using MySQL CHAR_LENGTH() function? Which function is the synonym of it?
- MySQL BIT_LENGTH() function is used for which purpose?
- Which PHP function is used to select a MySQL database?
- Which PHP function is used to create a MySQL table?
- How MySQL LENGTH() function measures the string length?
- How MySQL LOCATE() function is different from its synonym functions i.e. POSITION() and INSTR() functions?
- Which function in MySQL is used to reverse a particular string?
- What is the difference between MySQL LENGTH() and CHAR_LENGTH() function?
- Which MySQL function can be used to find out the length of the string in bits?
- Which function in MySQL returns the same output as BIN() function?
- Which PHP function is used to disconnect from MySQL database connection?
- Which PHP function is used to delete an existing MySQL table?
- Which MySQL function returns a specified number of characters of a string as output?
- Which MySQL function is used to find first non-NULL value from a list of values?
- Which PHP function is used to create a new database?