SQLite Ltrim() Function

  Total Views : 302
  Comments : 0
  Keywords : SQLite ltrim() function to remove whitespaces from left side with example, SQLite ltrim example to remove characters from starting of the string, SQLite ltrim to trim data from left side

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

SQLite Ltrim() Function

Generally in SQLite Ltrim() function is used to remove specified characters from 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 starting of the string. 

Syntax of SQLite Ltrim() Function

Following is the syntax of SQLite Ltrim() function to remove starting or left-hand side of specified characters from 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 left hand side.

 

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

 

In case we didn’t mentioned trim_character then ltrim() function will remove the spaces from 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 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 left-hand side of string.

 

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

 

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

 

ltrim('123321Tutlane123','123')

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

Tutlane123

If you observe above result it removed “123” characters from 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 above result it removed “12345” characters from 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 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 starting characters “sh” from first name of employees whose first name starts with “sh” from 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 above result the Ltrim() function removed starting characters “sh” from 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 string.

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User