oracle字符串如何简便去重? 比如说’123514543878645‘; 将字符内部重复的去掉变成‘12345678’。

我的思路是:
1、先把字符串打散,变成很多字符串,用“,”隔开!
2、去掉重复字符串!
3、重新组合!
想问有没有简单点的!!

使用以下函数即可完成:

--字符串去重复字符函数
CREATE OR REPLACE FUNCTION remove_rame_string(
v_strings in varchar2
)
return varchar2
IS
v_strings1 varchar2(64) default ' ';
begin
v_strings1:=nvl(replace(rtrim(ltrim(v_strings)),' ',''),' ');

select listagg(c, '') within group(order by id2) into v_strings1
from (select distinct c,id2
from (select row_number() over(partition by e.v_strings1 order by substr(e.v_strings1, iter.pos, 1)) rn,
substr(e.v_strings1, iter.pos, 1) c,1 as id2
from (select v_strings1 from dual) e,
(select rownum pos from user_tables) iter
where iter.pos <= length(e.v_strings1)
order by 1));
return v_strings1 ;

end remove_rame_string;
/
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-12-27
目前只想到自定义函数 通过循环来实现。。。。

循环 将每个字符写入一个临时表
然后
select distinct col1 from tmp_tb
这个怎么样。。。本回答被网友采纳
第2个回答  2012-12-27
用存储过程可以解决
相似回答