如何从PL / SQL中的字符串中删除所有非字母字符?

时间:2022-09-24 23:33:51

I have a PL/SQL procedure and I need to take a string and remove all characters that aren't alphabetic. I've seen some examples and read documentation about the REGEXP_REPLACE function but can't understand how it functions.

我有一个PL / SQL过程,我需要一个字符串并删除所有不是字母的字符。我已经看过一些示例并阅读有关REGEXP_REPLACE函数的文档,但无法理解它是如何工作的。

This is not a duplicate because I need to remove punctuation, not numbers.

这不是重复,因为我需要删除标点符号,而不是数字。

3 个解决方案

#1


2  

Either:

或者:

select regexp_replace('1A23B$%C_z1123d', '[^A-Za-z]') from dual;

or:

要么:

select regexp_replace('1A23B$%C_z1123d', '[^[:alpha:]]') from dual;

The second one takes into account possible other letters like:

第二个考虑可能的其他字母,如:

select regexp_replace('123żźć', '[^[:alpha:]]') from dual;

Result:

结果:

żźć

Also to answer your question about how the functions works: the first parameter is the source string, the second - a regular expression - everything which will be matched to it, will be replaced by the third argument (optional, NULL by default, meaning all matched characters will just be removed).

还要回答关于函数如何工作的问题:第一个参数是源字符串,第二个参数 - 正则表达式 - 将与之匹配的所有内容将被第三个参数替换(可选,默认情况下为NULL,表示全部匹配的字符将被删除)。

Read more about regular expressions:

阅读更多关于正则表达式:

http://docs.oracle.com/cd/B19306_01/appdev.102/b14251/adfns_regexp.htm

http://docs.oracle.com/cd/B19306_01/appdev.102/b14251/adfns_regexp.htm

#2


0  

you can use regexp like that:

你可以像这样使用正则表达式:

SELECT REGEXP_REPLACE(UPPER('xYztu-123-hello'), '[^A-Z]+', '') FROM DUAL;

also answered here for non-numeric chars

这里也回答了非数字字符

#3


0  

Try this:

尝试这个:

SELECT REGEXP_REPLACE('AB$%c','[^a-zA-Z]', '') FROM DUAL;

Or

要么

SELECT REGEXP_REPLACE( your_column, '[^a-zA-Z]', '' ) FROM your_table;

Read here for more information

请阅读此处了解更多信息

#1


2  

Either:

或者:

select regexp_replace('1A23B$%C_z1123d', '[^A-Za-z]') from dual;

or:

要么:

select regexp_replace('1A23B$%C_z1123d', '[^[:alpha:]]') from dual;

The second one takes into account possible other letters like:

第二个考虑可能的其他字母,如:

select regexp_replace('123żźć', '[^[:alpha:]]') from dual;

Result:

结果:

żźć

Also to answer your question about how the functions works: the first parameter is the source string, the second - a regular expression - everything which will be matched to it, will be replaced by the third argument (optional, NULL by default, meaning all matched characters will just be removed).

还要回答关于函数如何工作的问题:第一个参数是源字符串,第二个参数 - 正则表达式 - 将与之匹配的所有内容将被第三个参数替换(可选,默认情况下为NULL,表示全部匹配的字符将被删除)。

Read more about regular expressions:

阅读更多关于正则表达式:

http://docs.oracle.com/cd/B19306_01/appdev.102/b14251/adfns_regexp.htm

http://docs.oracle.com/cd/B19306_01/appdev.102/b14251/adfns_regexp.htm

#2


0  

you can use regexp like that:

你可以像这样使用正则表达式:

SELECT REGEXP_REPLACE(UPPER('xYztu-123-hello'), '[^A-Z]+', '') FROM DUAL;

also answered here for non-numeric chars

这里也回答了非数字字符

#3


0  

Try this:

尝试这个:

SELECT REGEXP_REPLACE('AB$%c','[^a-zA-Z]', '') FROM DUAL;

Or

要么

SELECT REGEXP_REPLACE( your_column, '[^a-zA-Z]', '' ) FROM your_table;

Read here for more information

请阅读此处了解更多信息