Purpose
TRIM() removes leading and/or trailing characters from a string.
Syntax
TRIM([{{ LEADING | TRAILING | BOTH }[ trim_character ]|trim_character }FROM] trim_source)
Parameters
| Parameter | Description |
|---|---|
| LEADING | TRAILING | BOTH | The location of the characters to be removed from the string.
|
| trim_character | The character to be removed. Only a single character can be specified for trim_character. If you do not specify trim_character, the default value is a blank space. |
| trim_source | The string that you want to trim. If you specify only trim_source, the function removes the leading and trailing blank spaces. |
Note
trim_character and trim_source can be VARCHAR2 or any data type that can be implicitly converted to VARCHAR2. If the function returns a value of the VARCHAR2 data type, the maximum length of the value is the length of the value of trim_source.
Return type
If
trim_sourceis of theCHARorVARCHAR2data type, the return type isVARCHAR2.If
trim_sourceis of theNCHARorNVARCHAR2data type, the return type isNVARCHAR2.If
trim_sourceis of theCLOBdata type, the return type isCLOB.If
trim_sourceortrim_characterisNULL, theTRIMfunction returnsNULL.
Examples
The following example removes the leading and trailing XX from XXOceanBaseXX.
obclient> SELECT TRIM('X' FROM 'XXOceanBaseXX') "TRIM" FROM DUAL;
+-----------+
| TRIM |
+-----------+
| OceanBase |
+-----------+
1 row in set