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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM