SQL TRIM, LTRIM, RTRIM


David Haertzen David Haertzen, Tutorial Author
Check out our
Data Warehousing Tutorial.
Previous | Next

SQL > SQL Advanced > SQL TRIM


What is SQL TRIM?

The SQL Trim feature is are functions (LTRIM and RTRIM) that remove leading and trailing blanks from a string.

For example, the function LTRIM(' Minnesota') returns:

'Minnesota'

Why Use SQL TRIM?

The SQL Trim functions (LTRIM and RTRIM) are useful in cleansing data that contains leading and trailing blanks.

How To Use SQL TRIM

SQL TRIM is used as follows.

SQL TRIM Syntax

 
SELECT LTRIM(<value_1>)
 
 
SELECT RTRIM(<value_1>)
 

SQL TRIM Example

The LTRIM function removes the leading blanks in the string ' Bob'.

This SQL Statement with LTRIM is executed:

 
SELECT LTRIM(' Bob ') as trimmed_string

Here is the result.

trimmed_string
Bob

Copyright© 1999-2015, First Place Software, Inc.