In MariaDB, RTRIM_ORACLE()
is a synonym for the Oracle mode version of the RTRIM()
function.
RTRIM_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 RTRIM()
function to behave like Oracle’s RTRIM()
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:
RTRIM_ORACLE(str)
Where str
is the string to remove any trailing spaces from.
Example
Here’s a basic example of how the trimming works:
SELECT
' Bruce Brewster ' AS "Untrimmed",
RTRIM_ORACLE(' Bruce Brewster ') AS "Trimmed";
Result:
+----------------------+-------------------+ | Untrimmed | Trimmed | +----------------------+-------------------+ | Bruce Brewster | Bruce Brewster | +----------------------+-------------------+
Here, the first column is untrimmed and the second one has been trimmed with RTRIM_ORACLE()
.
We can see that only the right part of the string is trimmed. The left part remains intact.
We can also see that the space within the string remains intact.
This is exactly how RTRIM()
works.
Empty Strings
Passing an empty string to RTRIM_ORACLE()
results in null
being returned.
SELECT RTRIM_ORACLE('');
Result:
+------------------+ | RTRIM_ORACLE('') | +------------------+ | NULL | +------------------+
This reflects the way Oracle’s RTRIM()
function deals with empty strings.
In MariaDB, the RTRIM()
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 RTRIM_ORACLE(null);
Result:
+--------------------+ | RTRIM_ORACLE(null) | +--------------------+ | NULL | +--------------------+
Missing Argument
Calling RTRIM_ORACLE()
without an argument results in an error:
SELECT RTRIM_ORACLE();
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'RTRIM_ORACLE'