Oracle删除重复的字符

Sup*_*ero 2 sql oracle plsql

为了实现密码复杂性,我需要一个可以删除重复字符的函数(为了生成符合密码复杂性要求的密码).因此,不再允许像weeeeee1这样的字符串,因为重复了e.我需要一个函数,它将返回we1,其中重复的字符已被删除.必须使用Oracle PL/SQL或直接sql.

我发现Oracle SQL - 从字符串中删除部分重复,但这不适用于我的weeeeee1测试用例,因为它只替换了一次迭代,因此返回weee1.

我不是要测试没有重复的字符.我正在尝试将重复的字符串更改为非重复的字符串.

Syl*_*oux 6

我认为您可以使用regexp_replace实现目标.或者我错过了什么?

select regexp_replace(:password, '(.)\1+','\1') 
  from dual;
Run Code Online (Sandbox Code Playgroud)

这是一个例子:

with t as (select 'weeee1' password from dual
           union select 'wwwwweeeee11111' from dual
           union select 'we1' from dual)

select regexp_replace(t.password, '(.)\1+','\1') 
  from t;
Run Code Online (Sandbox Code Playgroud)

生产:

REGEXP_REPLACE(T.PASSWORD,'(.)\1+','\1')
we1
we1
we1
Run Code Online (Sandbox Code Playgroud)