oracle字符串如何简便去重? 比如说’123514543878645‘; 将字符内部重复的去掉变成‘12345678’。 5
我的思路是:1、先把字符串打散,变成很多字符串,用“,”隔开!2、去掉重复字符串!3、重新组合!想问有没有简单点的!!...
我的思路是:
1、先把字符串打散,变成很多字符串,用“,”隔开!
2、去掉重复字符串!
3、重新组合!
想问有没有简单点的!! 展开
1、先把字符串打散,变成很多字符串,用“,”隔开!
2、去掉重复字符串!
3、重新组合!
想问有没有简单点的!! 展开
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;
/
--字符串去重复字符函数
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;
/
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询