tech on the net

Oracle/PLSQL: TRIM Function

Learn how to use the Oracle/PLSQL TRIM function with syntax and examples.


The Oracle/PLSQL TRIM function removes all specified characters either from the beginning or the ending of a string.


The syntax for the Oracle/PLSQL TRIM function is:

TRIM( [ LEADING | TRAILING | BOTH [ trim_character ] string1 )

Parameters or Arguments

LEADING - remove trim_character from the front of string1.

TRAILING - remove trim_character from the end of string1.

BOTH - remove trim_character from the front and end of string1.

trim_character is the character that will be removed from string1. If this parameter is omitted, the TRIM function will remove space characters from string1.

string1 is the string to trim.


If you do not choose a value for the first parameter (LEADING, TRAILING, BOTH), the TRIM function will remove trim_character from both the front and end of string1.

Applies To

The TRIM function can be used in the following versions of Oracle/PLSQL:

  • Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i


Let's look at some Oracle TRIM function examples and explore how you would use the TRIM function in Oracle/PLSQL.

For example:

TRIM('   tech   ') would return 'tech'
TRIM(' '  FROM  '   tech   ') would return 'tech'
TRIM(LEADING '0' FROM '000123') would return '123'
TRIM(TRAILING '1' FROM 'Tech1') would return 'Tech'
TRIM(BOTH '1' FROM '123Tech111') would return '23Tech'