SQLite RTRIM() Function
The SQLite RTRIM() function removes all specified characters from the right-hand side of a string.
Syntax
RTRIM(string, trim_characters)
Parameters
string |
Required. Specify the string to trim. |
trim_characters |
Optional. Specify characters to be trimmed from string. If omitted, spaces will be removed. |
Return Value
Returns the trimmed version of the specified string.
Example 1:
The example below shows the usage of RTRIM() function.
SELECT RTRIM('SQL Tutorial '); Result: 'SQL Tutorial' SELECT RTRIM(' SQL Tutorial '); Result: ' SQL Tutorial' SELECT RTRIM('John1', '1'); Result: 'John' SELECT RTRIM('John123', '123'); Result: 'John' SELECT RTRIM('123John123', '123'); Result: '123John' SELECT RTRIM('xxzyTRIMxyyz', 'xyz'); Result: 'xxzyTRIM'
Example 2:
Consider a database table called Employee. When the following INSERT statements are executed, the Name column will contain records with trailing spaces.
INSERT INTO Employee VALUES ('John ', 'London', 3000); INSERT INTO Employee VALUES ('Marry ', 'New York', 2750); INSERT INTO Employee VALUES ('Jo ', 'Paris', 2800); INSERT INTO Employee VALUES ('Kim ', 'Amsterdam', 3100); -- see the result SELECT * FROM Employee;
The query will produce the following result:
Name | City | Salary |
---|---|---|
John | London | 3000 |
Marry | New York | 2750 |
Jo | Paris | 2800 |
Kim | Amsterdam | 3100 |
To remove the trailing spaces from the Name column of the Employee table, the following query can be used:
UPDATE Employee SET Name = RTRIM(Name); -- see the result SELECT * FROM Employee;
This will produce the following result:
Name | City | Salary |
---|---|---|
John | London | 3000 |
Marry | New York | 2750 |
Jo | Paris | 2800 |
Kim | Amsterdam | 3100 |
❮ SQLite Functions