w3resource

SQLite rtrim() function

Description

SQLite rtrim() function returns a string formed by removing any and all characters that appear to the right side of a given string. If the argument which will be used to remove is omitted, spaces are removed.

Syntax:

rtrim(X)
rtrim(X,Y)

Argument:

Name Description
X A string whose trailing spaces are to be removed.
Y A string or character which will be removed from the right side of the string.

SQLite Version: 3.8.5

Example-1: SQLite rtrim() function

The following SQLite statement returns a string after removing all the trailing spaces of the argument string 'w3resource'.

SELECT 'w3resource '||'.com',rtrim('w3resource  ')||'.com';

Here is the result.

Sample Output:

'w3resource '||'.com'  rtrim('w3resource  ')||'.com'
---------------------  -----------------------------
w3resource .com        w3resource.com

Here in the above example shows that in the first column there are two spaces between 'w3resource' and '.com' but in the second column, there are no spaces, because of the rtrim() removes the trailing spaces from the string 'w3resource ' and concat the strings. Here we have used the '||' for concatenate two strings to explain it clearly that, how rtrim() works.

Example-2: SQLite rtrim() function

The following SQLite statement returns a string after removing the string 'test' from the string 'stringtest'.

select rtrim('stringtest','test');

Here is the result.

Sample Output:

rtrim('stringtest','test')
--------------------------
string

Here in the above example shows that the string 'test' mentioned in the 2nd argument have been removed from the given string and formed a new string 'string'

Example-3: SQLite rtrim() function using table

The following SQLite statement will display those rows after left trimming the first_name column by the string 'Al' where the first two characters of the first_name column like 'Al'.

Sample table: employees


SELECT employee_id,first_name,last_name,rtrim(first_name,'na')
FROM employees
WHERE first_name like '%na';

Here is the result.

Sample Output:

employee_id  first_name  last_name   rtrim(first_name,'na')
-----------  ----------  ----------  ----------------------
101          Neena       Kochhar     Nee
107          Diana       Lorentz     Di
141          Trenna      Rajs        Tre
196          Alana       Walsh       Al

From the above result, it seems that the first_name column indicating by red color have returned after trimming right by the string 'na'. All the letter 'n' and 'a' have been removed from right side of the string.

Previous: round()
Next: substr()



Follow us on Facebook and Twitter for latest update.