Removes the characters from the left side of str.
Usage notes
Take note of the following items:
If you do not specify trimChars, the spaces on the left side are removed by default.
If you specify trimChars, the substring that consists of one or more characters specified by trimChars is removed from the left side of the string that is specified by str.
Currently, the LTRIM function supports only English characters.
Syntax
string ltrim(string <str>[, <trimChars>])
string trim(leading [<trimChars>] from <str>)
Parameters
str: required. A value of the STRING type. This parameter specifies the string from the left side of which the characters are removed. If the input value is of the BIGINT, DECIMAL, DOUBLE, or DATETIME type, the value is implicitly converted into a value of the STRING type before calculation.
trimChars: optional. A value of the STRING type. This parameter specifies the characters to be removed.
Return value
A value of the STRING type is returned. The return value varies based on the following rules:
If the value of str is not of the STRING, BIGINT, DOUBLE, DECIMAL, or DATETIME type, an error is returned.
If the value of str or trimChars is null, null is returned.
Examples:
Example 1: Remove the space from the left side of string
yxTxyomxx
. Sample statement:-- The return value is yxTxyomxx . select ltrim(' yxTxyomxx '); -- The preceding statement is equivalent to the following statement: select trim(leading from ' yxTxyomxx ');
Example 2: Remove the substring that consists of one or more characters in the
xy
collection from the left side of the stringyxTxyomxx
.-- The return value is Txyomxx. If x or y appears on the left side, it is removed. select ltrim('yxTxyomxx', 'xy'); -- The preceding statement is equivalent to the following statement: select trim(leading 'xy' from 'yxTxyomxx');
Example 3: The input parameter is set to null. Sample statement:
-- The return value is null. select ltrim(null); select ltrim('yxTxyomxx', null);
Related functions
LTRIM is a string function. For more information about functions related to string searches and conversion, see String functions.