Book Contents

Book Index

Next Topic

Home

TRIM

TRIM combines the BTRIM, LTRIM, and RTRIM functions into a single function.

Syntax

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

Semantics

 

LEADING

removes the specified characters from the left side of the string

TRAILING

removes the specified characters from the right side of the string

BOTH

removes the specified characters from both sides of the string (default)

characters

(CHAR or VARCHAR) specifies the characters to remove from expression. The default is the space character.

expression

(CHAR or VARCHAR) is the string to trim

Examples

Retail_Schema=> SELECT '-' || TRIM(LEADING 'x' FROM 'xxdatabasexx') || '-';

?column?

--------------

-databasexx-

(1 row)

Retail_Schema=> SELECT '-' || TRIM(TRAILING 'x' FROM 'xxdatabasexx') || '-';

?column?

--------------

-xxdatabase-

(1 row)

Retail_Schema=> SELECT '-' || TRIM(BOTH 'x' FROM 'xxdatabasexx') || '-';

?column?

------------

-database-

(1 row)

Retail_Schema=> SELECT '-' || TRIM('x' FROM 'xxdatabasexx') || '-';

?column?

------------

-database-

(1 row)

Retail_Schema=> SELECT '-' || TRIM(LEADING FROM ' database ') || '-';

?column?

--------------

-database -

(1 row)

Retail_Schema=> SELECT '-' || TRIM(' database ') || '-';

?column?

------------

-database-

(1 row)