---
title: rtrim function
description: Learn the syntax of the rtrim function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/rtrim
---

# `rtrim` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Returns `str` with trailing characters removed.

## Syntax

```
rtrim( [trimStr ,] str)
```

## Arguments

* `trimStr`: An optional `STRING` expression with characters to be trimmed. The default is a space character.
* `str`: A `STRING` expression to be trimmed.

## Returns

A `STRING`.

The function removes any trailing characters within `trimStr` from `str`.

## Examples

```sql
> SELECT rtrim('SparkSQL   ') || '+';
 SparkSQL+

> SELECT rtrim('ab', 'SparkSQLabcaaba');
 SparkSQLabc

> SELECT rtrim('AB', 'SparkSQLabcaaba' COLLATE UTF8_BINARY);
 SparkSQLabcaaba

> SELECT rtrim('AB', 'SparkSQLabcaaba' COLLATE UTF8_LCASE);
 SparkSQLabc

-- RTRIM collation can be used instead of the rtrim function in many cases.
> SELECT 'hello' = rtrim('hello  '),
         'hello' = 'hello  ' COLLATE UTF8_BINARY_RTRIM;
   true true
```

## Related functions

* [`rpad` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/rpad.md)
* [`lpad` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/lpad.md)
* [`ltrim` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/ltrim.md)
* [`trim` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/trim.md)
* [Collation](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-collation.md)
