Purpose
This function is used to remove characters from the beginning and/or end of a string.
Syntax
TRIM([{{ LEADING | TRAILING | BOTH }[ trim_character ]|trim_character }FROM] trim_source)
Parameters
Parameter |
Description |
|---|---|
| LEADING | TRAILING | BOTH | Specifies the location from which to remove characters.
|
| trim_character | The character to be removed. It can be only a single character. If you do not specify the trim_character parameter, the default value is a space. |
| trim_source | The string from which to remove characters. If you specify only the trim_source parameter, leading and trailing spaces are removed. |
Note
Both trim_character and trim_source can be of the VARCHAR2 data type or any data type that can be implicitly converted to the VARCHAR2 data type. If the function returns a value of the VARCHAR2 data type, the maximum length of the value is the same as that of trim_source.
Return type
If
trim_sourceis of theCHARorVARCHAR2data type, the function returns a value of theVARCHAR2data type.If
trim_sourceis of theNCHARorNVARCHAR2data type, the function returns a value of theNVARCHAR2data type.If
trim_sourceis of theCLOBdata type, the function returns a value of theCLOBdata type.If
trim_sourceortrim_characterisNULL, theTRIMfunction returnsNULL.
Examples
Remove the XX characters from the beginning and end of the string XXOceanBaseXX.
obclient> SELECT TRIM('X' FROM 'XXOceanBaseXX') "TRIM" FROM DUAL;
+-----------+
| TRIM |
+-----------+
| OceanBase |
+-----------+
1 row in set
