

 Amazon Redshift 將不再支援從修補程式 198 開始建立新的 Python UDFs。現有 Python UDF 將繼續正常運作至 2026 年 6 月 30 日。如需詳細資訊，請參閱[部落格文章](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# RTRIM 函數
<a name="r_RTRIM"></a>

RTRIM 函數從字串結尾修剪一組指定的字元。移除只包含修剪字元清單中字元的最長字串。當修剪字元沒有出現在輸入字串中時，就會完成修剪。

## 語法
<a name="r_RTRIM-synopsis"></a>

```
RTRIM( string, trim_chars )
```

## 引數
<a name="r_RTRIM-arguments"></a>

 *string*   
要修剪的字串資料行、運算式或字串常值。

 *trim\$1chars*   
字串欄、運算式或字串常值，代表要從 *string* 結尾修剪的字元。如果未指定，則會使用空格作為修剪字元。

## 傳回類型
<a name="r_RTRIM-return-type"></a>

與 *string* 引數的資料類型相同的字串。

## 範例
<a name="r_RTRIM-example"></a>

下列範例從字串 `' abc '` 中修剪開頭和結尾空格：

```
select '     abc    ' as untrim, rtrim('     abc    ') as trim;

untrim    | trim
----------+------
   abc    |    abc
```

下列範例從字串 `'xyzaxyzbxyzcxyz'` 中移除結尾 `'xyz'` 字串。結尾的 `'xyz'` 已移除，但出現在字串內的部分則未移除。

```
select 'xyzaxyzbxyzcxyz' as untrim,
rtrim('xyzaxyzbxyzcxyz', 'xyz') as trim;

     untrim      |   trim
-----------------+-----------
 xyzaxyzbxyzcxyz | xyzaxyzbxyzc
```

下列範例會從符合 *trim \$1chars* 清單 `'tes'` 中任何字元的字串 `'setuphistorycassettes'` 中移除結尾部分。任何出現在輸入字串結尾的 *trim\$1chars* 清單中另一個字元前的 `t`、`e` 或 `s` 都會被移除。

```
SELECT rtrim('setuphistorycassettes', 'tes');

     rtrim      
-----------------
 setuphistoryca
```

下列範例修剪 VENUENAME 結尾出現的 'Park' 這幾個字元：

```
select venueid, venuename, rtrim(venuename, 'Park')
from venue
order by 1, 2, 3
limit 10;

venueid |         venuename          |          rtrim
--------+----------------------------+-------------------------
      1 | Toyota Park                | Toyota
      2 | Columbus Crew Stadium      | Columbus Crew Stadium
      3 | RFK Stadium                | RFK Stadium
      4 | CommunityAmerica Ballpark  | CommunityAmerica Ballp
      5 | Gillette Stadium           | Gillette Stadium
      6 | New York Giants Stadium    | New York Giants Stadium
      7 | BMO Field                  | BMO Field
      8 | The Home Depot Center      | The Home Depot Cente
      9 | Dick's Sporting Goods Park | Dick's Sporting Goods
     10 | Pizza Hut Park             | Pizza Hut
```

請注意，當 `P`、`a`、`r` 或 `k` 其中任何字元出現在 VENUENAME 的結尾時，RTRIM 會移除這些字元。