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 space characters by default.
Note that the trim()
function does not remove other whitespace characters by default.
Syntax
trim(string, character)
Code language: SQL (Structured Query Language) (sql)
Arguments
string
The source
string in which the character
will be removed.
character
The character
determines which character will be removed from the source string. It is an optional argument.
If the character
argument is omitted, the trim()
function will remove the spaces from both ends of the source
string.
Return Value
The trim()
function returns a new string with the specified leading and trailing characters removed. It does not change the source string.
Examples
The following statement returns a string without spaces at the beginning and end of a string.
SELECT trim(' SQLite trim ');
Code language: SQL (Structured Query Language) (sql)
trim(' SQLite trim ')
---------------------
SQLite trim
Code language: JavaScript (javascript)
The following statement removes the @
character at the beginning and the end of the string.
SELECT trim('@SQLite trim@@@','@');
Code language: SQL (Structured Query Language) (sql)
trim('@SQLite trim@@@','@')
---------------------------
SQLite trim
Code language: JavaScript (javascript)
The following statement removes leading and trailing spaces from artist names stored the artists
table:
UPDATE artists
SET Name = trim(Name);
Code language: SQL (Structured Query Language) (sql)