Skip to main content

LTRIM_IN

Description​

The LTRIM_IN function removes specified characters from the left side of a string. When no character set is specified, it removes leading spaces by default. When a character set is specified, it removes all specified characters from the left side (regardless of their order in the set). The key feature of LTRIM_IN is that it removes any combination of characters from the specified set, while the LTRIM function removes characters based on exact string matching.

Syntax​

LTRIM_IN(<str> [, <rhs>])

Parameters​

ParameterDescription
<str>The string to be processed. Type: VARCHAR
<rhs>Optional parameter, the set of characters to be removed. Type: VARCHAR

Return Value​

Returns VARCHAR type, representing the processed string.

Special cases:

  • If str is NULL, returns NULL
  • If rhs is not specified, removes all leading spaces
  • If rhs is specified, removes all characters from the left side that appear in rhs until encountering the first character not in rhs

Examples​

  1. Remove leading spaces
SELECT ltrim_in('   ab d') str;
+------+
| str |
+------+
| ab d |
+------+
  1. Remove specified character set
SELECT ltrim_in('ababccaab', 'ab') str;
+-------+
| str |
+-------+
| ccaab |
+-------+
  1. Comparison with LTRIM function
SELECT ltrim_in('abcd', 'ae'),ltrim('abcd', 'abe');
+------------------------+----------------------+
| ltrim_in('abcd', 'ae') | ltrim('abcd', 'abe') |
+------------------------+----------------------+
| bcd | abcd |
+------------------------+----------------------+