简体   繁体   中英

Removing spaces from a string, SQL

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 ''.

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.

Any help?

怎么样:

regexp_replace(:P14_search_text, '[[:space:]]*', '');

试试这个:

     Select Replace(:P14_search_text, ' ', '');

Hope this helps you,

SELECT REGEXP_REPLACE(' Any  String ','( ){1,}','') "REGEXP_REPLACE"  FROM DUAL;
SELECT REGEXP_REPLACE('  ','( ){1,}','') "REGEXP_REPLACE"  FROM DUAL;

the following query works for me in 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?

I tried the same method as @Don suggested and it works in oracle 10 xe.

select replace('     lkjds  d   s   adkj      ', ' ', '') from dual

result

lkjdsdsadkj

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM