SQL 中使用ltrim()去除左邊空格 ,rtrim()去除右邊空格 ,沒有同時去除左右空格的函數,要去除所有空格可以用replace(字符串,' ',''),將字符串里的空格替換為空 。 例:去除空格函數。
declare @temp char(50)
set @temp = ' hello sql '
print ltrim(@temp) --去除左邊空格
print rtrim(@temp) --去除右邊空格
print replace(@temp,' ','') --去除字符串里所有空格
print @temp
>> 輸出結果
hello sql
hello sql
hellosql
hello sql