今天在看程序时遇到函数ltrim(参数):在SQL编程中是删除前导空格之后的字符表达式。相当于C#中的trim()函数

主题链接图标 Transact-SQL 语法约定

语法

 
LTRIM ( character_expression )

参数

character_expression

字符数据或二进制数据的 表达式 。character_expression 可以是常量、变量或列。character_expression 必须属于某个可隐式转换为 varchar 的数据类型( text 、ntext 和 image 除外)。否则,请使用 CAST 显式转换 character_expression。

备注

兼容级别可能影响返回值。有关兼容级别的详细信息,请参阅 sp_dbcmptlevel (Transact-SQL)

返回类型

varchar 或 nvarchar

示例

以下示例使用 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
posted on 2007-10-09 09:42  ghxia  阅读(636)  评论(0编辑  收藏  举报