TRIM is a string manipulation function that manipulates all string data types (BIT, BLOB, and CHARACTER), and removes trailing and leading singletons from a string.
>>-TRIM--(--+----------------------------------------------+----> '-+-trim_singleton-------------------+-- FROM -' | .-BOTH-----. | '-+-LEADING--+--+----------------+-' '-TRAILING-' '-trim_singleton-' >--source_string--)--------------------------------------------><
TRIM returns a new string of the same type as source_string, in which the leading, trailing, or both leading and trailing singletons have been removed. The term singleton refers to a single part (BIT, BYTE, or CHARACTER) within a string of that type.
The singleton can contain a list of multiple characters to be trimmed from the source string.
Character | ' ' (space) |
---|---|
BLOB | X'00' |
Bit | B'0' |
If any parameter is NULL, the result is NULL.
It is often unnecessary to strip trailing blanks from character strings before comparison, because the rules of character string comparison mean that trailing blanks are not significant.
TRIM(TRAILING 'b' FROM 'aaabBb')
returns 'aaabB'. TRIM(' a ')
returns 'a'. TRIM(LEADING FROM ' a ')
returns 'a '. TRIM('b' FROM 'bbbaaabbb')
returns 'aaa'.DECLARE input1 CHARACTER 'testmgktest';
SET OutputRoot.XMLNSC.Top.Out1 = TRIM( 'ste' FROM input1);
The
preceding code produces the output message:<Top><Out1>mgk</Out1></Top>
DECLARE whiteSpace CONSTANT CHARACTER CAST( X'090D0A20' AS CHAR CCSID 1208);
/* tab, cr, lf, space */
DECLARE input2 CHARACTER 'smith';
SET input2 = whiteSpace || input2 || whiteSpace;
SET OutputRoot.XMLNSC.Top.Out2 = TRIM( whiteSpace FROM input2);
The
preceding code produces the output message:<Top><Out2>smith</Out2></Top>