SQL 字符串去除空格函数汇总

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

原文地址:https://www.cnblogs.com/thatzzz0414/p/13722840.html