Updated on 2026-11-06 GMT+08:00

ltrim

The ltrim function is used to remove characters from the left end of str:

  • If trimChars is not specified, spaces are removed by default.
  • If trimChars is specified, the characters in trimChars are treated as a set. The longest possible substring from the left end of str where all characters are in the trimChars set is removed.

Similar functions:

  • rtrim: The rtrim function removes characters from the right end of str.
  • trim: The trim function removes characters from both the left and right ends of str.

Syntax

ltrim([<trimChars>,] string <str>) 

Parameters

Parameter

Mandatory

Type

Description

str

Yes

STRING

The string from which to remove characters from the left end. If the input is of type BIGINT, DECIMAL, DOUBLE, or DATETIME, it is implicitly converted to STRING type before evaluation.

trimChars

No

STRING

The characters to be removed.

Return Values

Returns a value of type STRING.

  • If str is not of type STRING, BIGINT, DOUBLE, DECIMAL, or DATETIME, an error is returned.
  • If str or trimChars is NULL, NULL is returned.

Example Code

  • Remove the left spaces from the string abc. The command example is as follows.

    Returns the string abc.

    select ltrim('     abc');

    Equivalent to the following statement.

    select trim(leading from '     abc');

    leading indicates removing spaces from the beginning of the string.

  • The input parameter is NULL. The command example is as follows.

    Returns NULL.

    select ltrim(null);      select ltrim('xy', null);     select ltrim(null, 'xy');
  • Remove the substring from the left end of yxlucyxx where all characters are in the set xy.

    Returns lucyxx. Whenever an x or y is encountered at the left end, it is removed.

    select ltrim( 'xy','yxlucyxx');

    Equivalent to the following statement.

    select trim(leading 'xy' from 'yxlucyxx');