STRIP

The STRIP function takes a character expression and returns that expression with leading and/or trailing pad characters removed. Optional parameters indicate:

  • whether leading, or trailing, or both leading and trailing pad characters should be removed
  • which pad character to remove

Syntax

STRIP( stripSource { ',' striptype } { ',', stripCharacter } )

stripSource

The character expression to be stripped

stripType

Whether to strip from the left end, the right end, or both ends of the stripSource string. Specify this value unquoted, as shown in the examples below. You can use the full or short identifiers:

LEADING or L Strip characters from the left side of the string.
TRAILING or T Strip characters from the right side of the string.
BOTH or B Strip characters from both the left and right sides of the string.

If you don’t specify a stripType value, the default value of BOTH is used.

stripCharacter

A character expression, enclosed in single quotes, that specifies which character to strip from the source. If this is specified, it must evaluate to either NULL or to a character string whose length is exactly one. If left unspecified, it defaults to the space character (' ').

Results

If either stripCharacter or stripSource evaluates to NULL, the result of the STRIP function is NULL. Otherwise, the result is defined as follows:

  • If stripType is LEADING, the result will be the stripSource value with all leading occurrences of stripCharacter removed.
  • If stripType is TRAILING, the result will be the stripSource value with all trailing occurrences of stripCharacter removed.
  • If stripType is BOTH, the result will be the stripSource value with all leading AND trailing occurrences of stripCharacter removed.

If stripSource’s data type is CHAR or VARCHAR, the return type of the STRIP function will be VARCHAR. Otherwise the return type of the STRIP function will be CLOB.

Examples

splice> values strip('   space case   ', b);
1
----------------
space case

splice> values strip('   space case   ', both);
1
----------------
space case

splice> values strip('   space case   ', L);
1
----------------
space case

splice> values strip('   space case   ', LEADING);
1
----------------
space case

splice> values strip('   space case   ', t);
1
----------------
   space case

splice> values strip('   space case   ', TRAILING);
1
----------------
   space case

splice> values strip( 'aabbccaa', b, 'a');
1
--------
bbcc

splice> values strip( 'aabbccaa', l, 'a');
1
--------
bbccaa

splice> values strip( 'aabbccaa', t, 'a');
1
--------
aabbcc

See Also