Skip to main content
VeloDB Cloud 26.x·Apache Doris 4.x (≤ 4.0 supported)·"Since X.Y" tags refer to 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

ParameterDescription
<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

  1. Remove left spaces
SELECT LTRIM('   ab d');
+-------------------+
| LTRIM(' ab d') |
+-------------------+
| ab d |
+-------------------+
  1. Remove specified characters
SELECT LTRIM('ababccaab', 'ab');
+----------------------------+
| LTRIM('ababccaab', 'ab') |
+----------------------------+
| ccaab |
+----------------------------+
  1. NULL value handling
SELECT LTRIM(NULL), LTRIM('test', NULL);
+-------------+---------------------+
| LTRIM(NULL) | LTRIM('test', NULL) |
+-------------+---------------------+
| NULL | NULL |
+-------------+---------------------+
  1. Empty inputs
SELECT LTRIM(''), LTRIM('test', '');
+-----------+-------------------+
| LTRIM('') | LTRIM('test', '') |
+-----------+-------------------+
| | test |
+-----------+-------------------+
  1. Strip a multi-character prefix
SELECT LTRIM('abcdefg', 'abc'), LTRIM('123456', '12');
+-------------------------+-----------------------+
| LTRIM('abcdefg', 'abc') | LTRIM('123456', '12') |
+-------------------------+-----------------------+
| defg | 3456 |
+-------------------------+-----------------------+
  1. Entire string matches the trim chars
SELECT LTRIM('aaaaa', 'a'), LTRIM('   ', ' ');
+---------------------+-------------------+
| LTRIM('aaaaa', 'a') | LTRIM(' ', ' ') |
+---------------------+-------------------+
| | |
+---------------------+-------------------+
  1. 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 |
+--------------------------------------------+---------------------------------------+
  1. Strip a numeric prefix
SELECT LTRIM('000123', '0'), LTRIM('123abc123', '123');
+----------------------+---------------------------+
| LTRIM('000123', '0') | LTRIM('123abc123', '123') |
+----------------------+---------------------------+
| 123 | abc123 |
+----------------------+---------------------------+
  1. Strip a punctuation prefix
SELECT LTRIM('---text---', '-'), LTRIM('@@hello@@', '@');
+--------------------------+-------------------------+
| LTRIM('---text---', '-') | LTRIM('@@hello@@', '@') |
+--------------------------+-------------------------+
| text--- | hello@@ |
+--------------------------+-------------------------+