Rtrim Function In Sql in SQL
? RTRIM() Function in SQL
The RTRIM() function removes trailing spaces (spaces at the end) from a string.
? Syntax:
RTRIM(string)string: The input string from which trailing spaces will be removed.
? Example 1: Remove trailing spaces
SELECT RTRIM('Hello World ') AS trimmed_string;Output:
| trimmed_string |
|---|
| Hello World |
(Note: spaces after "World" are removed)
? Example 2: When string has no trailing spaces
SELECT RTRIM('Hello') AS trimmed_string;Output:
| trimmed_string |
|---|
| Hello |
? Usage:
Clean up strings before storing or comparing
Formatting outputs
Prevent unexpected spaces in data processing
? Supported in:
SQL Server
MySQL (as
RTRIM())Oracle (uses
RTRIM()too)PostgreSQL (use
rtrim())
? Related Functions:
| Function | Description |
|---|---|
LTRIM() | Removes leading spaces |
TRIM() | Removes leading & trailing |
Need help with trimming both sides using TRIM()?