MariaDB RTRIM_ORACLE() Function

In MariaDB, RTRIM_ORACLE() is a built-in string function that returns a string with all the trailing whitespaces removed.

The RTRIM_ORACLE() function is a synonym for the RTRIM() function.

If you want to remove leading spaces from a string, use the LTRIM() or LTRIM_ORACLE() function;

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

MariaDB RTRIM_ORACLE() Syntax

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

RTRIM_ORACLE(str)

Parameters

str

Required. Strings that need to remove trailing whitespaces.

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

Return value

The MariaDB RTRIM_ORACLE() function returns strings with trailing spaces removed. The function replaces the returned empty string with the NULL value.

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

MariaDB RTRIM_ORACLE() Examples

Basic example

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

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

Output:

+---------------------------+----------------------------------------+
| RTRIM_ORACLE('   Hello ') | CHAR_LENGTH(RTRIM_ORACLE('   Hello ')) |
+---------------------------+----------------------------------------+
|    Hello                  |                                      8 |
+---------------------------+----------------------------------------+

In this example, we use the CHAR_LENGTH() function. CHAR_LENGTH(RTRIM_ORACLE(' Hello ')) returned 8 , which means that RTRIM_ORACLE() only removed trailing spaces.

Empty string

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

In default mode, the following statement will return an empty string:

SELECT RTRIM_ORACLE('   ');

Output:

+---------------------+
| RTRIM_ORACLE('   ') |
+---------------------+
| NULL                |
+---------------------+

This behaves exactly like the RTRIM() function.

Conclusion

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