SQLite ltrim() Function

The SQLite ltrim() function removes the longest string containing all the characters specified by the parameter (whitespace by default) from the start a string.

You can also use rtrim() to remove specified characters from the end of a string.

Syntax

This is the syntax of the SQLite ltrim() function:

ltrim(str)

or

ltrim(str, characters)

Parameters

str

Required. The string to trim.

characters

Optional. A string containing characters to remove. The default is a space.

Return value

The SQLite ltrim() function removes the longest string containing all the characters specified by the parameter (a space by default) from the start of the gaven string str, and returns the character-removed string.

Examples

This example shows the basic usage of the SQLite ltrim() function:

SELECT
    length(ltrim('a  ')),
    length(ltrim('  a')),
    length(ltrim(' a '));
length(ltrim('a  '))  length(ltrim('  a'))  length(ltrim(' a '))
--------------------  --------------------  --------------------
3                     1                     2

Here:

  • We’ve only used one parameter, so ltrim() removed spaces from the start of the string.
  • To make the result look more intuitive, we used length() function to display the length of the trimed string.

Let’s use ltrim() to remove specified characters from the start of a string:

SELECT ltrim('xxyHELLOzxy', 'xyz');
ltrim('xxyHELLOzxy', 'xyz')
---------------------------
HELLOzxy

Here, since we specified the characters xyz to be deleted, xxy in the start of xxyHELLOzxy is removed.