从字符串中删除空格,SQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13846017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Removing spaces from a string, SQL
提问by Raúl Nú?ez Cuevas
I'm trying to write a SQL query that will remove all spaces so that if a string only has spaces the final string is just ''.
我正在尝试编写一个 SQL 查询,该查询将删除所有空格,以便如果字符串只有空格,则最终字符串只是 ''。
I've tried this code but apparently it isn't working for more than one space:
我试过这段代码,但显然它不适用于多个空间:
regexp_replace(:P14_search_text, '( ){1,}', '')
Being :P14_search_text
the string I want to modify.
正在:P14_search_text
我要修改的字符串。
Any help?
有什么帮助吗?
回答by Julien May
how about:
怎么样:
regexp_replace(:P14_search_text, '[[:space:]]*', '');
回答by Don
try this:
尝试这个:
Select Replace(:P14_search_text, ' ', '');
回答by Mari
Hope this helps you,
希望这对你有帮助,
SELECT REGEXP_REPLACE(' Any String ','( ){1,}','') "REGEXP_REPLACE" FROM DUAL;
SELECT REGEXP_REPLACE(' ','( ){1,}','') "REGEXP_REPLACE" FROM DUAL;
回答by nullrevolution
the following query works for me in oracle:
以下查询在 oracle 中对我有用:
select
:tst_val AS INPUT,
regexp_replace(:tst_val, '[[:space:]]*', '') AS MODIFIED
from
dual
if this query does not work for you, would you show us what results you're getting?
如果这个查询对你不起作用,你能告诉我们你得到了什么结果吗?
回答by hahn
I tried the same method as @Don suggested and it works in oracle 10 xe.
我尝试了与@Don 建议的方法相同的方法,它在 oracle 10 xe 中有效。
select replace(' lkjds d s adkj ', ' ', '') from dual
result
结果
lkjdsdsadkj