SQL 字符串去除空格函数

来源:互联网 发布:专辑封面 知乎 编辑:程序博客网 时间:2024/05/14 08:23

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

原创粉丝点击