Compresses the string and returns a value of type LONG BINARY.
COMPRESS( string-expression [ , 'compression-algorithm-alias' ])
string-expression The string to be compressed. Binary values can be passed to this function. This parameter is case sensitive, even in case-insensitive databases.
compression-algorithm-alias Alias for the algorithm to use for compression. The supported values are zip and gzip (both are based on the same algorithm, but use different headers and trailers).
Zip is a widely supported compression algorithm. Gzip is compatible with the gzip utility on Unix, whereas the zip algorithm is not.
Decompression must be performed with the same algorithm.
For more information, see DECOMPRESS function [String].
The COMPRESS function returns a LONG BINARY value that is usually shorter than the binary string passed to the function. This value is not human-readable. If the value returned is longer than the original string, its maximum size will not be larger than a 0.1% increase over the original string + 12 bytes. You can decompress a compressed string-expression using the DECOMPRESS function.
If you are storing compressed values in a table, the column should be BINARY or LONG BINARY so that character set conversion is not performed on the data.
SQL/2003 Vendor extension.
The following example returns the length of the binary string created by compressing the string 'Hello World' using the gzip algorithm. This example can be useful when you want to determine whether a value has a shorter length when compressed.
SELECT LENGTH( COMPRESS( 'Hello world', 'gzip' ) );