SQLite trim() function

Valento - Net Worth Tracker App
Your data has a schema. Your finances should too.
Track accounts, assets, debts, and net worth in one clear view.
Get Valento for iPhone 

The SQLite trim() function removes specified characters at the beginning and the end of a string.

If you don’t specify the characters to remove, the trim() function will remove the space characters.

Note that the trim() function does not remove other whitespace characters by default.

Syntax #

trim(string, character)

Arguments #

string
The input string that you want to remove the character.

character

The character determines which characters you want to remove from the input string. It is an optional argument.

If you omit the character argument, the trim() function will remove the spaces from both ends of the input string.

Return value #

The trim() function returns a new string with the specified leading and trailing characters removed. It does not change the input string.

Examples #

The following statement uses the trim() function to return a string without spaces at the beginning and end of a string.

SELECT trim('   SQLite trim   ') result;

Try it

Output:

result
-----------
SQLite trim

The following example uses the trim() function to remove the USD string from a USD amount so 400USD becomes 400:

SELECT trim('400USD','USD') amount;

Try it

Output:

amount
------
400

The following example uses the trim() function to remove the $ symbol at the beginning of a USD amount:

SELECT trim('$400','$') amount;

Try it

Output:

amount
------
400

The following statement uses the trim() function in the UPDATE statement to remove leading and trailing spaces from artist names in the artists table:

UPDATE artists
SET Name = trim(Name);

Try it

Was this tutorial helpful?