Purpose
You can call this function to remove 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_characterandtrim_sourcecan beVARCHAR2or any data type that can be implicitly converted toVARCHAR2. If the function returns a value of theVARCHAR2data type, the maximum length of the value is the length of the value oftrim_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