LTRIM (Transact-SQL)

傳回移除開頭空白的字元運算式。

主題連結圖示Transact-SQL 語法慣例

語法

LTRIM ( character_expression )

引數

  • character_expression
    這是字元或二進位資料的運算式。character_expression 可以是常數、變數或資料行。character_expression 必須是在 text、ntext 和 image 之外,可隱含地轉換成 varchar 的資料類型。否則,請利用 CAST 來明確轉換 character_expression。

傳回類型

varchar 或nvarchar

備註

相容性層級可能會影響傳回值。如需有關相容性層級的詳細資訊,請參閱<sp_dbcmptlevel (Transact-SQL)>。

範例

下列範例會利用 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)