SQLite Ltrim() Function

Here we will learn what is SQLite Ltrim() function and how to use SQLite Ltrim() function to remove specified characters from the starting or left side of the string.

SQLite Ltrim() Function

Generally in SQLite Ltrim() function is used to remove specified characters from the left-hand side or starting of the string.

 

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

Syntax of SQLite Ltrim() Function

Following is the syntax of SQLite Ltrim() function to remove the starting or left-hand side of specified characters from a string.

 

ltrim( string, trim_character )

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

 

string – Its source string which used to trim characters from the left-hand side.

 

trim_character – The trim_character is a character that we need to remove from the starting or left-hand side of a string. It’s Optional.

 

In case we didn’t mention trim_character then ltrim() function will remove the spaces from the starting or left-hand side of the source string.

SQLite Ltrim() Function Examples

Now we will see how to use SQLite ltrim() function to remove the starting or left-hand side of characters with examples.

 

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

 

ltrim("--------Tutlane--","-")

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

Tutlane--

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

 

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

 

sqliteSELECT ltrim('123321Tutlane123','123');

 

ltrim('123321Tutlane123','123')

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

Tutlane123

If you observe the above result it removed “123” characters from the left-hand of string using ltrim() function.

 

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

 

sqliteSELECT ltrim('4153Tutlane123','12345');

 

ltrim('4153Tutlane123','12345')

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

Tutlane123

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

SQLite Ltrim() Function with Tables

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

 

To create and insert some data in the 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 starting characters “sh” from the first name of employees whose first name starts with “sh” from the emp_master table.

 

sqliteSELECT emp_id,first_name,ltrim(first_name,'Sh')

FROM emp_master

WHERE first_name LIKE 'Sh%';

 

emp_id      first_name  trim(first_name,'Sh')

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

2           Shweta      weta

5           Shweta      weta

9           Shwets      wets

If you observe the above result, the Ltrim() function removed starting characters “sh” from the first_name column in emp_master table whose first_name column like 'Sh'.

 

This is how we can use SQLite Ltrim() function to remove starting or left-hand side characters from a string.