我有这个字符串
ABCD1234, XYZ, ABCD1234, ABCD1234C, ABCD1234, abc, abcX, 1234U, 1234
我想要,但我不想要重复值
ABCD1234, XYZ, ABCD1234C, abc, abcX, 1234U, 1234,
我正在使用以下正则表达式
select regexp_replace (
'ABCD1234, XYZ, ABCD1234, ABCD1234C, ABCD1234, abc, abcX, 1234U, 1234',
'([^,]+)(,\1)+', '\1'
) test
from dual;
答案 0 :(得分:0)
根据文章http://www.dba-oracle.com/t_extract_comma_delimited_strings_oracle_sql.html尝试此操作:
select distinct str from
(select regexp_substr ('ABCD1234, XYZ, ABCD1234, ABCD1234C, ABCD1234, abc, abcX, 1234U, 1234', '[^, ]+',1, rownum) str
from dual
connect by level <= regexp_count ('ABCD1234, XYZ, ABCD1234, ABCD1234C, ABCD1234, abc, abcX, 1234U, 1234', '[^, ]+')) v;
答案 1 :(得分:0)
这是一个选项:
SQL> with test (id, col) as
2 (select 1, 'ABCD1234, XYZ, ABCD1234, ABCD1234C, ABCD1234, abc, abcX, 1234U, 1234' from dual union
3 select 2, '111, 222, 111, ABCX2, FFE, 222' from dual
4 ),
5 t_rows as
6 (select id, regexp_substr(col, '[^, ]+', 1, column_value) col
7 from test,
8 table(cast(multiset(select level from dual
9 connect by level <= regexp_count(col, ',') + 1)
10 as sys.odcinumberlist))
11 ),
12 t_distinct as
13 (select distinct id, col
14 from t_rows
15 )
16 select id, listagg(col, ', ') within group (order by null) col
17 from t_distinct
18 group by id;
ID COL
---------- --------------------------------------------------
1 1234, 1234U, ABCD1234, ABCD1234C, XYZ, abc, abcX
2 111, 222, ABCX2, FFE
SQL>