SQLite Rtrim() Function

  Total Views : 220
  Comments : 0
  Keywords : SQLite rtrim() function to remove whitespaces from end of the string with example, SQLite rtrim example to remove characters from right side of string, SQLite rtrim function to trim data

Here we will learn what is SQLite Rtrim() function and how to use SQLite Rtrim() function to remove specified characters from ending or right hand side of string.

SQLite Rtrim() Function

Generally in SQLite Rtrim() function is used to remove specified characters from right-hand side or ending of the string.

 

In case if we didn’t specify any characters to remove for Rtrim() function, then it will remove only space characters from ending of the string. 

Syntax of SQLite Rtrim() Function

Following is the syntax of SQLite Rtrim() function to remove ending or right-hand side of specified characters from string.

 

 

rtrim( string, trim_character )

 

In above SQLite rtrim() function syntax we defined multiple parameters those are

 

string – Its source string which is used to trim characters from right hand side.

 

trim_character – The trim_character is a character which we need to remove from ending or right-hand side of string. It’s Optional.

 

In case we didn’t mentioned trim_character then rtrim() function will remove the spaces from ending or right-hand side of the source string.

SQLite Rtrim() Function Examples

Now we will see how to use SQLite rtrim() function to remove ending or right-hand side of characters with examples.

 

sqliteSELECT rtrim("--Tutlane-----","-");

 

rtrim("--Tutlane-----","-")

---------------------------

--Tutlane

If you observe above result the SQLite rtrim() function removed specified characters from right-hand side of string.

 

Following is the another example of using SQLite rtrim() function to remove right-hand side of characters from string.

 

sqliteSELECT rtrim('123Tutlane123321','123');

 

rtrim('123Tutlane123321','123')

--------------------------------

123Tutlane

If you observe above result rtrim() function removed “123” characters from right-hand of string.

 

Following is the another example of using SQLite rtrim() function to remove right-hand side of characters from string.

 

sqliteSELECT rtrim('123Tutlane4153','12345');

 

rtrim('123Tutlane4153','12345')

--------------------------------

123Tutlane

If you observe above result it removed “12345” characters from right-hand of string using rtrim() function.

SQLite Rtrim() Function with Tables

Now we will see how to use Rtrim() function in SQLite tables with examples for that we need to create table called emp_master using following query.

 

To create and insert some data in emp_master table execute following query.

 

CREATE TABLE emp_master

(emp_id INTEGER PRIMARY KEY AUTOINCREMENT,

first_name TEXT,

last_name TEXT,

salary NUMERIC,

dept_id INTEGER);

 

INSERT INTO emp_master

values (1,'Honey','Patel', 10100,1),

(2,'Shweta','Jariwala', 19300,2),

(3,'Vinay','Jariwala', 35100,3),

(4,'Jagruti','Viras', 9500,2),

(5,'Shweta','Rana',12000,3),

(6,'sonal','Menpara', 13000,1),

(7,'Yamini','Patel', 10000,2),

(8,'Khyati','Shah', 50000,3),

(9,'Shwets','Jariwala',19400,2);

Now run the following query to check the records of emp_master table.

 

sqliteSELECT FROM emp_master;

 

emp_id      first_name  last_name   salary      dept_id

----------  ----------  ----------  ----------  ----------

1           Honey       Patel       10100       1

2           Shweta      Jariwala    19300       2

3           Vinay       Jariwala    35100       3

4           Jagruti     Viras       9500        2

5           Shweta      Rana        12000       3

6           Sonal       Menpara     13000       1

7           Yamini      Patel       10000       2

8           Khyati      Shah        50000       3

9           Shwets      Jariwala    19400       2

Now write the query like as shown following to remove ending characters “ti” from first name of employees whose first name ends with “ti” from emp_master table.

 

sqlite> SELECT emp_id,first_name,rtrim(first_name,'ti')

FROM emp_master

WHERE first_name LIKE '%ti';

 

emp_id      first_name  rtrim(first_name,'ti')

----------  ----------  ----------------------

4           Jagruti     Jagru

8           Khyati      Khya

If you observe above example result it returns first name column values after trimming the right side of string with “ti”.

 

This is how we can use SQLite Rtrim() function to remove the right side characters from string based on our requirements. 

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User