且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Oracle Regexp 用空格替换 、 和

更新时间:2023-02-23 10:49:28

不需要正则表达式.这可以通过 ASCII 代码和无聊的旧 TRANSLATE() 轻松完成

No need for regex. This can be done easily with the ASCII codes and boring old TRANSLATE()

select translate(your_column, chr(10)||chr(11)||chr(13), '    ')
from your_table;

这将用空格替换换行符、制表符和回车符.

This replaces newline, tab and carriage return with space.

TRANSLATE() 比它的正则表达式更有效.但是,如果您决定采用这种方法,您应该知道我们可以在正则表达式中引用 ASCII 代码.所以这个语句是上面的正则表达式版本.

TRANSLATE() is much more efficient than its regex equivalent. However, if your heart is set on that approach, you should know that we can reference ASCII codes in regex. So this statement is the regex version of the above.

select regexp_replace(your_column,  '([x0A|x0B|`x0D])', ' ')
from your_table;

调整是以十六进制而不是基数 10 引用 ASCII 代码.

The tweak is to reference the ASCII code in hexadecimal rather than base 10.