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 intrimCharsis treated as an individual member of the removal set — not as a prefix substring.
Return value
Returns a STRING value.
If
stris not of STRING, BIGINT, DOUBLE, DECIMAL, or DATETIME type, an error is returned.If
strortrimCharsis 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 ');| Input | Result |
|---|---|
' 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');| Input | trimChars | Result |
|---|---|---|
'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.