Sql 不带空格的Oracle regexp
我需要将两个单词之间没有空格的所有地方,其中第一个以点结尾,替换为这两个单词之间有空格的地方 例如,我有像Sql 不带空格的Oracle regexp,sql,oracle,regexp-replace,regexp-substr,Sql,Oracle,Regexp Replace,Regexp Substr,我需要将两个单词之间没有空格的所有地方,其中第一个以点结尾,替换为这两个单词之间有空格的地方 例如,我有像'num.some'这样的字符串,我需要'num.some' 但是如果我有'num.some',我就不需要'num.some'(类似的东西可能会帮助你: WITH examples AS ( SELECT 'num.some' str FROM dual UNION SELECT 'num. some' str FROM dual UNION SELECT '123.
'num.some'
这样的字符串,我需要'num.some'
但是如果我有
'num.some'
,我就不需要'num.some'
(类似的东西可能会帮助你:
WITH examples AS (
SELECT 'num.some' str FROM dual
UNION
SELECT 'num. some' str FROM dual
UNION
SELECT '123.4' str FROM dual
UNION
SELECT '123.some' str FROM dual
)
SELECT str, REGEXP_REPLACE(str,'([a-zA-Z0-9]+)\.([a-zA-Z]+)','\1. \2') replaced
FROM examples
这将查找字母后面的一个点,后面是一个不带空格的字母这将查找所有组合(letter.letter、letter.digit、digit.letter),并在.之后添加一个空格,同时保持digit.digit不变
with
inputs ( str ) as (
select 'ab.sw' from dual union all
select 'ab. sw' from dual union all
select '12.33' from dual union all
select '12. 33' from dual union all
select 'ab.123' from dual union all
select '1. ab' from dual union all
select '1.abc' from dual
)
-- END test data. Solution (SQL query) begins below this line.
select str, regexp_replace(str,
'(([[:alpha:]]\.)([[:alpha:]])|([[:alpha:]]\.)(\d)|(\d\.)([[:alpha:]]))',
'\2\4\6 \3\5\7') as new_str
from inputs
;
STR NEW_STR
------ -------
ab.sw ab. sw
ab. sw ab. sw
12.33 12.33
12. 33 12. 33
ab.123 ab. 123
1. ab 1. ab
1.abc 1. abc
也许您不需要regexp.Plain
replace()
可能很适合您
(关于@mathguy的测试数据)
请发布您到目前为止尝试过的内容以及您遇到的问题。数据中是否有
一些.123
,是否还需要添加空格?第二个单词后重复两次。我有'dol.USA',这个是'dol.USA.USA',我不明白为什么?@anastasiasordia它也在为我使用'dol.USA'
with
inputs ( str ) as (
select 'ab.sw' from dual union all
select 'ab. sw' from dual union all
select '12.33' from dual union all
select '12. 33' from dual union all
select 'ab.123' from dual union all
select '1. ab' from dual union all
select '1.abc' from dual
)
-- END test data. Solution (SQL query) begins below this line.
select replace(
replace(str, '.', '. ') -- replace all dots by dot+space
, ' '
, ' '
) -- replace all double spaces by a single space
from inputs
;