Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

TRIM() - Remove characters

Function group: string function

TRIM() removes leading and/or trailing characters of a string.


TRIM ([[LEADING | TRAILING | BOTH][ character ] FROM] expression)

character ::= expression



character / expression

character and expression are either both alphanumeric expressions (data type CHAR or VARCHAR) or both national expressions (data type NCHAR or NVARCHAR). Neither of the operands may be a multiple value with a dimension greater than 1. The value of character has the length 1. If you do not specify character, the default is a blank ().


FROM

FROM operator; you can only specify FROM is you also specify LEADING, TRAILING or BOTH and/or character.


Result

If character and/or expression returns the NULL value, the result is the NULL value.

Otherwise:

The result is a copy of the string returned when expression is evaluated, except that leading and/or trailing characters that correspond to the value of character are removed. Whether leading or trailing characters are removed depends on whether you specify LEADING, TRAILING or BOTH:

LEADING:  Leading characters are removed.

TRAILING: Trailing characters are removed.

BOTH:        Leading and trailing characters are removed. BOTH is the default.

Data type:

If expression has the alphanumeric data type CHAR( n) or VARCHAR( n), the result has the alphanumeric data type VARCHAR( n).

If expression has the national data type NCHAR(n) or NVARCHAR(n), the result has the national data type NVARCHAR(n).


Examples


The following examples are equivalent and return 'ABC'.

TRIM(' ABC ')

TRIM (BOTH ' ' FROM ' ABC ')


The following example returns 'BLE WAS I ERE I SAW ELB'.

TRIM (BOTH N'N' FROM N'NURDUGUDRUN')


A record is inserted in the table PROFESSORS. The form_of_address column in the table has the data type VARCHAR(50). It is to receive the value 'Professor'.
The corresponding COBOL user variable has the data type PIC X(50). To ensure that only the value 'Professor' rather than the value 'Professor...' with 36 trailing characters is transferred, you use the TRIM string function:

INSERT INTO professors (..., form_of_address, ...)

VALUES (..., TRIM (TRAILING FROM :FORM_OF_ADDRESS), ...)