forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: Su, Xiaomeng <suxiaomeng1@huawei.com> Co-committed-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
9.4 KiB
9.4 KiB
rtrim
This function is used to remove characters from the right of str.
- If trimChars is not specified, spaces are removed by default.
- If trimChars is specified, the function removes the longest possible substring from the right end of str that consists of characters in the trimChars set.
Similar functions:
- ltrim. This function is used to remove characters from the left of str.
- trim. This function is used to remove characters from the left and right of str.
Syntax
rtrim([<trimChars>, ]string <str>)
or
rtrim(trailing [<trimChars>] from <str>)
Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
str |
Yes |
STRING |
String from which characters on the right are to be removed. If the value is of the BIGINT, DECIMAL, DOUBLE, or DATETIME type, the value is implicitly converted to the STRING type for calculation. |
trimChars |
Yes |
STRING |
Characters to be removed |
Return Values
The return value is of the STRING type.
Example Code
- Removes spaces on the right of the string yxabcxx. An example command is as follows:
The value yxabcxx is returned.
select rtrim('yxabcxx ');
It is equivalent to the following statement:
select trim(trailing from ' yxabcxx ');
- Removes all substrings from the right end of the string yxabcxx that consist of characters in the set xy.
The function returns yxabc, as any substring starting with x or y from the right end is removed.
select rtrim('xy', 'yxabcxx');
It is equivalent to the following statement:
select trim(trailing 'xy' from 'yxabcxx');
- The value of the input parameter is NULL. An example command is as follows:
The value NULL is returned.
select rtrim(null); select ltrim('yxabcxx', 'null');
Parent topic: String Functions