VeloDB Cloud 26.x·Apache Doris 4.x (up to 4.0 supported)·"Since X.Y" tags refer to Apache Doris versionsVersion mapping
LTRIM
Description
The LTRIM function removes consecutive occurrences of spaces or specified character sets from the left side (beginning) of a string. This function scans from the left end of the string and removes all consecutive target characters until it encounters a character not in the target character set.
Syntax
LTRIM(<str> [, <trim_chars>])
Parameters
| Parameter | Description |
|---|---|
<str> | The source string to be left-trimmed. Type: VARCHAR |
<trim_chars> | Optional parameter, specifies the set of characters to remove. If not provided, defaults to removing space characters. Type: VARCHAR |
Return Value
Returns VARCHAR type, representing the string after removing specified characters from the left side.
Trimming rules:
- Only removes characters from the left side (beginning) of the string
- Removes all consecutive characters that appear in trim_chars
- Stops removing once a character not in trim_chars is encountered
- If trim_chars is not specified, defaults to removing space characters (including spaces, tabs, newlines, etc.)
Special cases:
- If any parameter is NULL, returns NULL
- If str is empty string, returns empty string
- If trim_chars is empty string, returns original string
- If entire string consists of characters in trim_chars, returns empty string
Examples
- Remove left spaces
SELECT LTRIM(' ab d');
+-------------------+
| LTRIM(' ab d') |
+-------------------+
| ab d |
+-------------------+
- Remove specified characters
SELECT LTRIM('ababccaab', 'ab');
+----------------------------+
| LTRIM('ababccaab', 'ab') |
+----------------------------+
| ccaab |
+----------------------------+
- NULL value handling
SELECT LTRIM(NULL), LTRIM('test', NULL);
+-------------+---------------------+
| LTRIM(NULL) | LTRIM('test', NULL) |
+-------------+---------------------+
| NULL | NULL |
+-------------+---------------------+
- Empty inputs
SELECT LTRIM(''), LTRIM('test', '');
+-----------+-------------------+
| LTRIM('') | LTRIM('test', '') |
+-----------+-------------------+
| | test |
+-----------+-------------------+
- Strip a multi-character prefix
SELECT LTRIM('abcdefg', 'abc'), LTRIM('123456', '12');
+-------------------------+-----------------------+
| LTRIM('abcdefg', 'abc') | LTRIM('123456', '12') |
+-------------------------+-----------------------+
| defg | 3456 |
+-------------------------+-----------------------+
- Entire string matches the trim chars
SELECT LTRIM('aaaaa', 'a'), LTRIM(' ', ' ');
+---------------------+-------------------+
| LTRIM('aaaaa', 'a') | LTRIM(' ', ' ') |
+---------------------+-------------------+
| | |
+---------------------+-------------------+
- UTF-8 substring strip (the second arg is matched as a literal substring, not a character set)
SELECT LTRIM('ṭṛìṭṛì test', 'ṭṛì'), LTRIM('ḍḍuḍḍu hello', 'ḍu');
+--------------------------------------------+---------------------------------------+
| LTRIM('ṭṛìṭṛì test', 'ṭṛì') | LTRIM('ḍḍuḍḍu hello', 'ḍu') |
+--------------------------------------------+---------------------------------------+
| test | ḍḍuḍḍu hello |
+--------------------------------------------+---------------------------------------+
- Strip a numeric prefix
SELECT LTRIM('000123', '0'), LTRIM('123abc123', '123');
+----------------------+---------------------------+
| LTRIM('000123', '0') | LTRIM('123abc123', '123') |
+----------------------+---------------------------+
| 123 | abc123 |
+----------------------+---------------------------+
- Strip a punctuation prefix
SELECT LTRIM('---text---', '-'), LTRIM('@@hello@@', '@');
+--------------------------+-------------------------+
| LTRIM('---text---', '-') | LTRIM('@@hello@@', '@') |
+--------------------------+-------------------------+
| text--- | hello@@ |
+--------------------------+-------------------------+