MariaDB LTRIM_ORACLE() Function

In MariaDB, LTRIM_ORACLE() is a built-in string function that returns a string with all the leading whitespace removed.

The LTRIM_ORACLE() function is a synonym for LTRIM() in Oracle mode.

If you want to remove trailing spaces from a string, use RTRIM() or RTRIM_ORACLE().

If you want to remove both leading and trailing spaces from a string, use TRIM() or TRIM_ORACLE().

MariaDB LTRIM_ORACLE() Syntax

Here is the syntax of the MariaDB LTRIM_ORACLE() function:

LTRIM_ORACLE(str)

Parameters

str

Required. A string that needs to have leading whitespace removed.

If you do not provide a parameter, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'LTRIM_ORACLE'.

Return value

The MariaDB LTRIM_ORACLE() function returns a string with leading spaces removed. The function returns NULL instead of the empty string.

If the argument is NULL, the LTRIM_ORACLE() function will return NULL.

MariaDB LTRIM_ORACLE() Examples

Basic example

To remove leading spaces from ' Hello ', use the following statement:

SELECT
  LTRIM_ORACLE('   Hello '),
  CHAR_LENGTH(LTRIM_ORACLE('   Hello '));

Output:

+---------------------------+----------------------------------------+
| LTRIM_ORACLE('   Hello ') | CHAR_LENGTH(LTRIM_ORACLE('   Hello ')) |
+---------------------------+----------------------------------------+
| Hello                     |                                      6 |
+---------------------------+----------------------------------------+

In this example, we use the CHAR_LENGTH() function. CHAR_LENGTH(LTRIM_ORACLE(' Hello ')) returned 6, which means that LTRIM_ORACLE() only removed leading spaces.

Empty string

The LTRIM_ORACLE() returns NULL instead of the empty string.

SELECT LTRIM_ORACLE('   ');

Output:

+---------------------+
| LTRIM_ORACLE('   ') |
+---------------------+
| NULL                |
+---------------------+

This behaves exactly like the LTRIM() function in Oracle mode.

Conclusion

In MariaDB, LTRIM_ORACLE() is a built-in string function that returns a string with all the leading whitespace characters removed.