TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str), TRIM([remstr FROM] str)
Returns the string str
with all remstr
prefixes or suffixes removed. If none of the specifiers BOTH
, LEADING
, or TRAILING
is given, BOTH
is assumed. remstr
is optional and, if not specified, spaces are removed.
Returns NULL if given a NULL argument. If the result is empty, returns either an empty string, or, from MariaDB 10.3.6 with SQL_MODE=Oracle, NULL.
The Oracle mode version of the function can be accessed outside of Oracle mode by using TRIM_ORACLE
as the function name.
SELECT TRIM(' bar ')\G *************************** 1. row *************************** TRIM(' bar '): bar SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx')\G *************************** 1. row *************************** TRIM(LEADING 'x' FROM 'xxxbarxxx'): barxxx SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx')\G *************************** 1. row *************************** TRIM(BOTH 'x' FROM 'xxxbarxxx'): bar SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz')\G *************************** 1. row *************************** TRIM(TRAILING 'xyz' FROM 'barxxyz'): barx
Oracle mode version from MariaDB 10.3.6:
SELECT TRIM(''),TRIM_ORACLE(''); +----------+-----------------+ | TRIM('') | TRIM_ORACLE('') | +----------+-----------------+ | | NULL | +----------+-----------------+
© 2019 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/trim/