RTRIM 截断所有尾随空格后返回一个字符串。语法 RTRIM ( character_expression ) 参数 character_expression由字符数据组成的表达式。character_expression 可以是常量、变量,也可以是字符或二进制数据的列。返回类型 varchar注释 character_expression 必须为可隐性转换为 varchar 的数据类型。否则请使用 CAST 函数显式转换 character_expression。说明 兼容级别可能影响返回值。有关更多信息,请参见 sp_dbcmptlevel。 示例 下例显示如何使用 RTRIM 删除字符变量中的尾随空格。DECLARE @string_to_trim varchar(60) SET @string_to_trim = 'Four spaces are after the period in this sentence. ' SELECT 'Here is the string without the leading spaces: ' + CHAR(13) + RTRIM(@string_to_trim) GO下面是结果集:(1 row(s) affected) ------------------------------------------------------------------------ Here is the string without the leading spaces: Four spaces are after the period in this sentence. (1 row(s) affected)
LTRIM 删除起始空格后返回字符表达式。语法 LTRIM ( character_expression )参数 character_expression是字符或二进制数据表达式。character_expression 可以是常量、变量或列。character_expression 必须是可以隐性转换为 varchar 的数据类型。否则,使用 CAST 显式转换 character_expression。返回类型 varchar注释 兼容级别可能影响返回值。有关兼容级别的更多信息,请参见 sp_dbcmptlevel。 示例 下例使用 LTRIM 字符删除字符变量中的起始空格。DECLARE @string_to_trim varchar(60) SET @string_to_trim = ' Five spaces are at the beginning of this string.' SELECT 'Here is the string without the leading spaces: ' + LTRIM(@string_to_trim) GO下面是结果集:------------------------------------------------------------------------ Here is the string without the leading spaces: Five spaces are at the beginning of this string. (1 row(s) affected)
截断所有尾随空格后返回一个字符串。语法
RTRIM ( character_expression ) 参数
character_expression由字符数据组成的表达式。character_expression 可以是常量、变量,也可以是字符或二进制数据的列。返回类型
varchar注释
character_expression 必须为可隐性转换为 varchar 的数据类型。否则请使用 CAST 函数显式转换 character_expression。说明 兼容级别可能影响返回值。有关更多信息,请参见 sp_dbcmptlevel。
示例
下例显示如何使用 RTRIM 删除字符变量中的尾随空格。DECLARE @string_to_trim varchar(60)
SET @string_to_trim = 'Four spaces are after the period in this sentence. '
SELECT 'Here is the string without the leading spaces: ' + CHAR(13) +
RTRIM(@string_to_trim)
GO下面是结果集:(1 row(s) affected)
------------------------------------------------------------------------
Here is the string without the leading spaces: Four spaces are after the period in this sentence.
(1 row(s) affected)
删除起始空格后返回字符表达式。语法
LTRIM ( character_expression )参数
character_expression是字符或二进制数据表达式。character_expression 可以是常量、变量或列。character_expression 必须是可以隐性转换为 varchar 的数据类型。否则,使用 CAST 显式转换 character_expression。返回类型
varchar注释
兼容级别可能影响返回值。有关兼容级别的更多信息,请参见 sp_dbcmptlevel。 示例
下例使用 LTRIM 字符删除字符变量中的起始空格。DECLARE @string_to_trim varchar(60)
SET @string_to_trim = ' Five spaces are at the beginning of this
string.'
SELECT 'Here is the string without the leading spaces: ' +
LTRIM(@string_to_trim)
GO下面是结果集:------------------------------------------------------------------------
Here is the string without the leading spaces: Five spaces are at the beginning of this string. (1 row(s) affected)
用第三个表达式替换第一个字符串表达式中出现的所有第二个给定字符串表达式。语法
REPLACE ( 'string_expression1' , 'string_expression2' , 'string_expression3' )参数
'string_expression1'待搜索的字符串表达式。string_expression1 可以是字符数据或二进制数据。'string_expression2'待查找的字符串表达式。string_expression2 可以是字符数据或二进制数据。'string_expression3'替换用的字符串表达式。string_expression3 可以是字符数据或二进制数据。返回类型
如果 string_expression(1、2 或 3)是支持的字符数据类型之一,则返回字符数据。如果 string_expression(1、2 或 3)是支持的 binary 数据类型之一,则返回二进制数据。示例
下例用 xxx 替换 abcdefghi 中的字符串 cde。SELECT REPLACE('abcdefghicde','cde','xxx')
GO下面是结果集:------------
abxxxfghixxx