T-SQL,删除字符串中的空格 [英] T-SQL, Remove space in string
本文介绍了T-SQL,删除字符串中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 SQL 中有两个字符串,而 REPLACE 函数只对其中一个起作用,这是为什么?
I have two strings in SQL and the REPLACE function only works on one of them, why is that?
示例 1:
SELECT REPLACE('18 286.74', ' ', '')
示例 2:
SELECT REPLACE('z z', ' ', '')
示例 1 的输出仍然是18 286.74",而示例 2 的输出是zz".为什么 SQL 对两个字符串的反应方式不同?
Example 1's output is still "18 286.74" whereas Example 2's output is "zz". Why does SQL not react the same way to both strings?
更新:
当运行 select replace('123 123.12', ' ', '')
时,工作正常,但仍然不是 '18 286.74'.
When running select replace('123 123.12', ' ', '')
that works fine, still not with '18 286.74'.
推荐答案
按以下方式测试.
select unicode(substring('18 286.74', 3, 1))
如果代码返回 32 那么它是一个空格,如果不是,它是一个不同的 Unicode 字符,你的替换 ' ' 将不起作用.
If the code returns 32 then it's a space, if not, it's a different Unicode character and your replace ' ' won't work.
这篇关于T-SQL,删除字符串中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文