MySQL COMPRESS() function
COMPRESS() function
MySQL COMPRESS() function compress a string and returns the result as a binary string.
Nonempty strings are stored as a four-byte length of the uncompressed string (low byte first), followed by the compressed string. If the string ends with space, an extra "." character is added to avoid problems with end space trimming.
Empty strings are stored as empty strings.
Syntax:
COMPRESS(string_to_compress);
Argument:
Name | Description |
---|---|
string_to_compress | A string which is to be compressed. |
Syntax Diagram:

MySQL Version: 8.0
Example
Code:
SELECT COMPRESS('text'),LENGTH(COMPRESS('text'));
Explanation:
The above MySQL statement will compress the string text and also returns the length of the string after compression.
Output:
mysql> SELECT COMPRESS('text'),LENGTH(COMPRESS('text')); +------------------+--------------------------+ | COMPRESS('text') | LENGTH(COMPRESS('text')) | +------------------+--------------------------+ | xœ+I( gÆ | 16 | +------------------+--------------------------+ 1 row in set (0.03 sec)
Previous: AES_ENCRYPT()
Next: DECODE()
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join