SQL 字串去除空格函式

2021-08-31 02:42:06 字數 412 閱讀 3920

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

SQL 字串去除空格函式

sql 中使用ltrim 去除左邊空格 rtrim 去除右邊空格 沒有同時去除左右空格的函式,要去除所有空格可以用replace 字串,將字串裡的空格替換為空 例 去除空格函式。declare temp char 50 set temp hello sql print ltrim temp 去除左邊...

SQL 字串去除空格函式

sql 中使用ltrim 去除左邊空格 rtrim 去除右邊空格 沒有同時去除左右空格的函式,要去除所有空格可以用replace 字串,將字串裡的空格替換為空 例 去除空格函式。declare temp char 50 set temp hello sql print ltrim temp 去除左邊...

js去除字串空格

方法一 使用replace正則匹配的方法 去除所有空格 str str.replace s g,去除兩頭空格 str str.replace s s g,去除左空格 str str.replace s 去除右空格 str str.replace s g,str為要去除空格的字串,例項如下 var s...