All Products
Search
Document Center

MaxCompute:LTRIM

Last Updated:Mar 26, 2026

Removes characters from the left side of a string.

Syntax

string ltrim(string <str>[, <trimChars>])
string trim(LEADING [<trimChars>] FROM <str>)

Parameters

  • str: Required. STRING type. BIGINT, DECIMAL, DOUBLE, and DATETIME values are implicitly converted to STRING before processing.

  • trimChars: Optional. STRING type. The set of characters to remove from the left side of str. Defaults to ' ' (a single space). If specified, every character in trimChars is treated as an individual member of the removal set — not as a prefix substring.

Return value

Returns a STRING value.

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

  • If str or trimChars is null, null is returned.

Usage notes

  • LTRIM only supports English strings.

Examples

Example 1: Remove the leading space from a string

SELECT ltrim(' yxTxyomxx ');
-- Equivalent:
SELECT trim(LEADING FROM ' yxTxyomxx ');
InputResult
' yxTxyomxx ''yxTxyomxx '

The trailing space is preserved. Only the leading space is removed.

Example 2: Remove a set of characters from the left side

SELECT ltrim('yxTxyomxx', 'xy');
-- Equivalent:
SELECT trim(LEADING 'xy' FROM 'yxTxyomxx');
InputtrimCharsResult
'yxTxyomxx''xy''Txyomxx'

x and y are each treated as individual characters in the removal set. Removal stops at T, the first character not in the set. The xy sequence within Txyomxx is not touched.

Example 3: Null input

SELECT ltrim(null);
SELECT ltrim('yxTxyomxx', null);

Both return null.

Related functions

LTRIM is a string function. For more information about related string functions, see String functions.