RTRIM (Transact-SQL)
适用于:SQL Server(所有受支持的版本)
Azure SQL 数据库
Azure SQL 托管实例
Azure Synapse Analytics
Analytics Platform System (PDW)
截断所有尾随空格后返回一个字符串。
语法
RTRIM ( character_expression )
注意
若要查看 SQL Server 2014 及更早版本的 Transact-SQL 语法,请参阅早期版本文档。
参数
character_expression
字符数据的表达式。 character_expression 可以是常量、变量,也可以是字符列或二进制数据列。
character_expression 的数据类型必须可隐式转换为 varchar。 否则,请使用 CAST 显式转换 character_expression。
返回类型
varchar 或 nvarchar
示例
A. 简单示例
以下示例将接受一个在句子结尾包含空格的字符串,并返回在句子结尾没有空格的文本。
SELECT RTRIM('Removes trailing spaces. ');
下面是结果集。
Removes trailing spaces.
B. 简单示例
以下示例显示如何使用 RTRIM
删除尾随空格。 此时会有另一个字符串连接到第一个字符串,显示空格已删除。
SELECT RTRIM('Four spaces are after the period in this sentence. ') + 'Next string.';
下面是结果集。
Four spaces are after the period in this sentence.Next string.
C. 将 RTRIM 用于变量
以下示例显示如何使用 RTRIM
删除字符变量中的尾随空格。
DECLARE @string_to_trim VARCHAR(60);
SET @string_to_trim = 'Four spaces are after the period in this sentence. ';
SELECT @string_to_trim + ' Next string.';
SELECT RTRIM(@string_to_trim) + ' Next string.';
GO
下面是结果集。
Four spaces are after the period in this sentence. Next string.
Four spaces are after the period in this sentence. Next string.
另请参阅
LEFT (Transact-SQL)
LTRIM (Transact-SQL)
RIGHT (Transact-SQL)
STRING_SPLIT (Transact-SQL)
SUBSTRING (Transact-SQL)
TRIM (Transact-SQL)
CAST 和 CONVERT (Transact-SQL)
数据类型 (Transact-SQL)
字符串函数 (Transact-SQL)