Oracle / PLSQL: TRIM Function

This article is written about how to use the Oracle/PLSQL TRIM function with syntax and examples.

Description

The Oracle/PLSQL TRIM feature removes all certain characters both from the beginning or the end of a string.

Syntax

The syntax for the TRIM feature in Oracle/PLSQL is:

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

Parameters or Arguments

LEADING The function will put off trim_character from the front of string1. TRAILING The feature will take away trim_character from the stop of string1. BOTH The function will get rid of trim_character from the front and quit of string1. trim_character The character that will be removed from string1. If this parameter is omitted, the TRIM characteristic will remove space characters from string1. string1 The string to trim.

Returns

The TRIM function returns a string value.

Note

If you do now not select a fee for the first parameter (LEADING, TRAILING, BOTH), the TRIM function will do away with trim_character from each the the front and stop of string1. See additionally the LTRIM and RTRIM functions.

Applies To

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

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

Example

Let’s seem to be at some Oracle TRIM feature examples and discover how to use the TRIM function in Oracle/PLSQL.

For example:

TRIM('   tech   ')
Result: 'tech'

TRIM(' '  FROM  '   tech   ')
Result: 'tech'

TRIM(LEADING '0' FROM '000123')
Result: '123'

TRIM(TRAILING '1' FROM 'Tech1')
Result: 'Tech'

TRIM(BOTH '1' FROM '123Tech111')
Result: '23Tech'