Collections:
FORMAT_BYTES() - Formatting Bytes in Readable Units
How to format a number of bytes in a human-readable unit using the FORMAT_BYTES() function?
✍: FYIcenter.com
FORMAT_BYTES(con) is a MySQL built-in function that
converts a number of bytes in a human-readable unit of KiB, MiG, GiB, TiB, PiB or EiB.
For example:
SELECT FORMAT_BYTES(9), FORMAT_BYTES(9*1024), FORMAT_BYTES(9*1024*1024); -- +-----------------+----------------------+---------------------------+ -- | FORMAT_BYTES(9) | FORMAT_BYTES(9*1024) | FORMAT_BYTES(9*1024*1024) | -- +-----------------+----------------------+---------------------------+ -- | 9 bytes | 9.00 KiB | 9.00 MiB | -- +-----------------+----------------------+---------------------------+ SELECT FORMAT_BYTES(9*POW(1024,3)), FORMAT_BYTES(9*POW(1024,4)); -- +-----------------------------+-----------------------------+ -- | FORMAT_BYTES(9*POW(1024,3)) | FORMAT_BYTES(9*POW(1024,4)) | -- +-----------------------------+-----------------------------+ -- | 9.00 GiB | 9.00 TiB | -- +-----------------------------+-----------------------------+ SELECT FORMAT_BYTES(9*POW(1024,5)), FORMAT_BYTES(9*POW(1024,6)); -- +-----------------------------+-----------------------------+ -- | FORMAT_BYTES(9*POW(1024,5)) | FORMAT_BYTES(9*POW(1024,6)) | -- +-----------------------------+-----------------------------+ -- | 9.00 PiB | 9.00 EiB | -- +-----------------------------+-----------------------------+
Reference information of the FORMAT_BYTES() function:
FORMAT_BYTES(bytes): str Converts a number of bytes in a human-readable unit of KiB, MiG, GiB, TiB, PiB or EiB. Arguments, return value and availability: bytes: Required. The number of bytes to be converted. str: Return value. The converted number in a human-readable unit. Available since MySQL 8.0.
⇒ EXP() - Exponential Based on E
⇐ FORMAT() - Formatting Number to String
2025-09-24, 915🔥, 0💬
Popular Posts:
How To Convert Character Strings into Numeric Values in SQL Server Transact-SQL? Sometimes you need ...
What Are Bitwise Operations in SQL Server Transact-SQL? Bitwise operations are binary operations per...
What Is the Difference Between GETDATE() and GETUTCDATE() in SQL Server Transact-SQL? The difference...
How To Convert a Unicode Strings to Non-Unicode Strings in SQL Server Transact-SQL? Since Unicode ch...
What are single-byte character string data types supported in SQL Server Transact-SQL? Single-byte c...