Collections:
LENGTH() - Number of Bytes in String
How to count the number of bytes of a giving string using the LENGTH() function?
✍: FYIcenter.com
LENGTH(string) is a MySQL built-in function that returns the
number of bytes of a giving string. For example:
SET @string = 'Bonjour Françoise';
SELECT LENGTH(@string), CHAR_LENGTH(@string);
-- +-----------------+----------------------+
-- | LENGTH(@string) | CHAR_LENGTH(@string) |
-- +-----------------+----------------------+
-- | 18 | 17 |
-- +-----------------+----------------------+
SELECT LENGTH('O'), LENGTH('©'), LENGTH('😋');
-- +-------------+--------------+----------------+
-- | LENGTH('O') | LENGTH('©') | LENGTH('😋') |
-- +-------------+--------------+----------------+
-- | 1 | 2 | 4 |
-- +-------------+--------------+----------------+
SELECT HEX('O'), HEX('©'), HEX('😋');
-- +----------+-----------+-------------+
-- | HEX('O') | HEX('©') | HEX('😋') |
-- +----------+-----------+-------------+
-- | 4F | C2A9 | F09F988B |
-- +----------+-----------+-------------+
Reference information of the LENGTH() function:
LENGTH(str): num Returns the length of the string str, measured in bytes. A multibyte character counts as multiple bytes. This means that for a string containing five 2-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5. Returns NULL if str is NULL. Arguments, return value and availability: str: Required. The given string to count the number of bytes for. num: Return value. The number of bytes in the given string. Available since MySQL 4.0.
Related MySQL functions:
⇒ LOCATE() - Locate Substring Starting at N
2023-11-10, 1287🔥, 0💬
Popular Posts:
How To Connect ASP Pages to Oracle Servers in Oracle? If you are running Windows IIS Web server and ...
What Is a Parameter File in Oracle? A parameter file is a file that contains a list of initializatio...
How To Get Year, Month and Day Out of DATETIME Values in SQL Server Transact-SQL? You can use DATEPA...
What To Do If the StartDB.bat Failed to Start the XE Instance in Oracle? If StartDB.bat failed to st...
Where to find SQL Server Transact-SQL language references? You can find SQL Server Transact-SQL lang...