In MariaDB, LTRIM_ORACLE()
is a synonym for the Oracle mode version of the LTRIM()
function.
LTRIM_ORACLE()
is available in all modes, so it saves you from having to switch to Oracle mode, which is what you’d need to do if you wanted the LTRIM()
function to behave like Oracle’s LTRIM()
function.
The difference is in how each function treats empty strings. Oracle returns null
whereas MariaDB returns an empty string.
Syntax
The syntax goes like this:
LTRIM_ORACLE(str)
Where str
is the string to remove any leading spaces from.
Example
Here’s a basic example of how the trimming works:
SELECT
' Jumping Jack ' AS "Untrimmed",
LTRIM_ORACLE(' Jumping Jack ') AS "Trimmed";
Result:
+--------------------+-----------------+ | Untrimmed | Trimmed | +--------------------+-----------------+ | Jumping Jack | Jumping Jack | +--------------------+-----------------+
Here, the first column is untrimmed and the second one has been trimmed with LTRIM_ORACLE()
.
We can see that only the left part of the string is trimmed. The right part is left intact.
We can also see that the space within the string is left intact.
This is exactly how LTRIM()
works.
Empty Strings
Passing an empty string to LTRIM_ORACLE()
results in null
being returned.
SELECT LTRIM_ORACLE('');
Result:
+------------------+ | LTRIM_ORACLE('') | +------------------+ | NULL | +------------------+
This reflects the way Oracle’s LTRIM()
function deals with empty strings.
In MariaDB, the LTRIM()
function only returns null
when you’re using Oracle mode. When not in Oracle mode, it returns an empty string.
Null Argument
If the argument is null
, the result is null
:
SELECT LTRIM_ORACLE(null);
Result:
+--------------------+ | LTRIM_ORACLE(null) | +--------------------+ | NULL | +--------------------+
Missing Argument
Calling LTRIM_ORACLE()
without an argument results in an error:
SELECT LTRIM_ORACLE();
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'LTRIM_ORACLE'