TRIM

From Oracle FAQ
Jump to: navigation, search

TRIM, LTRIM and RTRIM are SQL functions used to filter unwanted characters from strings. By default they remove spaces, but a set of characters can be specified for removal as well.

TRIM[edit]

TRIM will remove leading and trailing characters. Syntax:

trim ( string-to-be-trimmed [, characters ] );

Example:

SELECT trim ('   removing spaces from both sides   ') FROM dual;

LTRIM[edit]

Trim from the left side of the string. Syntax:

ltrim ( string-to-be-trimmed [, characters ] );

Example:

SELECT ltrim ('   removing spaces from the left side') FROM dual;

RTRIM[edit]

Trim from the right side of the string. Syntax:

rtrim ( string-to-be-trimmed [, characters ] );

Example:

SELECT rtrim ('removing spaces from the right side   ') FROM dual;