替换字符串中点后的空格

Replace spaces after a dot in the string

我想在 Oracle 中编写查询以删除字符串中任何点之后的所有空格。 示例:

select 'My name is Pramod. I am writing a query. Today is AUG 16TH.' from dual;

请求的输出是:

My name is Pramod.I am writing a query.Today is AUG 16TH.

一个简单的 replace,基于您的简单示例:

SQL> with test (col) as
  2    (select 'My name is Pramod. I am writing a query' from dual)
  3  select replace(col, '. ', '.') result
  4  from test;

RESULT
--------------------------------------
My name is Pramod.I am writing a query

SQL>

对于不那么简单的例子:

SQL> with test (col) as
  2    (select 'My name is Pramod. I am writing a query' from dual union all
  3     select 'Right.   As @Mathguy said. It won''t work.always' from dual
  4    )
  5  select regexp_replace(col, '\. +', '.') result
  6  from test;

RESULT
--------------------------------------------------------------------------------
My name is Pramod.I am writing a query
Right.As @Mathguy said.It won't work.always

SQL>

试试这个:

select regexp_replace('My name is Pramod. I am writing a query. Today is AUG 16TH.','\.(\s)*','.') 
from dual

Sql fiddle Demo

干杯!!

这也行。

select regexp_replace( 'Right.   As @Mathguy said. It won''t work.always' ,'(\.)([[:space:]]*)', '.' )  from dual;