COMPRESS Function

Returns a character string with specified characters removed from the original string.

Category: Character
Returned data type: CHAR, NCHAR

Syntax

Arguments

character-expression

specifies any valid expression that evaluates to a character expression and from which specified characters will be removed.

Requirement Enclose a literal string of characters in single quotation marks.
Data type CHAR, NCHAR
See <sql-expression>
FedSQL Expressions

character-list-expression

specifies a variable or any valid expression that initializes a list of characters.

By default, the characters in this list are removed from character-expression.
Requirement Enclose a literal string of characters in single quotation marks.
Data type CHAR, NCHAR
See <sql-expression>
FedSQL Expressions

Details

The COMPRESS function allows null arguments. A null argument is treated as a string that has a length of zero.
Based on the number of arguments, the COMPRESS functions works as follows:
Number of Arguments
Results
Only the first argument, source
All blanks have been removed. If the argument is completely blank, then the result is a string with a length of zero. If you assign the result to a character variable with a fixed length, then the value of that variable will be padded with blanks to fill its defined length.
Two arguments, source and chars
All characters that appear in the second argument are removed from the result.
To remove digits and plus or minus signs, you could use the following function call:
COMPRESS(source, "1234567890+-");

Example

This example shows how to remove characters from a string.
Statements
Results
----+----1----+----2----+----3
select compress('abc','a');
 
 bc

See Also

Functions:
Last updated: February 23, 2017