SQLite ltrim() function


The ltrim() function returns a string formed by removing any and all characters that appear in the second argument(N) from the left side of the first argument(M). If the N argument is omitted, ltrim(M) removes spaces from the left side of M.




Name Description
M A string whose leading space characters are to be removed.
N optional. character(s) to be removed, if omitted leading spaces to be removed.

Pictorial Presentation

SQLite LTRIM() pictorial presentation

Example-1: SQLite ltrim() function

The following SQLite statement returns the string ‘ Hello’ after removing the leading space characters. In the output, the first column shows the string with leading space characters and the second column shows the string after performing ltrim.

SELECT ' Hello'as "Original String", ltrim(' Hello');

Sample Output:

Original String  ltrim(' Hello')
---------------  ---------------
 Hello           Hello

The above result shows the original string ' Hello' displayed from down the second character of heading 'Original String' but after ltrim it returns just down the first character of the heading 'ltrim(' Hello')'.

Example-2: SQLite ltrim() function

The following SQLite statement returns the string ‘disqualify’ after removing the leading characters 'dis' from the left side.

SELECT 'disqualify',ltrim('disqualify','dis');

Sample Output:

'disqualify'  ltrim('disqualify','dis')
------------  ------------------------
disqualify    qualify

The above result shows that the first three characters i.e. 'dis' have removed from the given string.

Example-3: SQLite ltrim() 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,ltrim(first_name,'Al')
FROM employees
WHERE first_name like 'Al%';

Here is the result.

Sample Output:

employee_id  first_name  last_name   ltrim(first_name,'Al')
-----------  ----------  ----------  ----------------------
103          Alexander   Hunold      exander
115          Alexander   Khoo        exander
147          Alberto     Errazuriz   berto
158          Allan       McEwen      an
175          Alyssa      Hutton      yssa
185          Alexis      Bull        exis
196          Alana       Walsh       ana

From the above result, it seems that the first_name column indicating by red color have returned after trimming left by the string 'Al'

Previous: lower()
Next: nullif()

Follow us on Facebook and Twitter for latest update.