首页 > 数据库技术 > 详细

oracle 字符串中去掉重复的字符串

时间:2015-12-30 19:13:27      阅读:679      评论:0      收藏:0      [点我收藏+]

create or replace function MyReplace(oldStr varchar2, sign varchar2) return varchar2 is

str varchar2(1000);

currentIndex number;

startIndex number;

endIndex number;

type str_type is table of varchar2(30)

index by binary_integer;

arr str_type;

Result varchar2(1000);

begin

if oldStr is null then

return (‘‘);

end if;

str := oldStr;

currentIndex := 0;

startIndex := 0;

loop

currentIndex := currentIndex + 1;

endIndex := instr(str, sign, 1, currentIndex);

if (endIndex <= 0) then

exit;

end if;

arr(currentIndex) := trim(substr(str, startIndex + 1, endIndex - startIndex - 1));

startIndex := endIndex;

end loop;

arr(currentIndex) := substr(str, startIndex + 1, length(str));

for i in 1.. currentIndex - 1 loop

for j in i + 1..currentIndex loop

if arr(i) = arr(j) then

arr(j) := ‘‘;

end if;

end loop;

end loop;

str := ‘‘;

for i in 1..currentIndex loop

if arr(i) is not null then

str := str || sign || arr(i);

arr(i) := ‘‘;

end if;

end loop;

Result := substr(str, 2, length(str));

return(Result);

end MyReplace;

oracle 字符串中去掉重复的字符串

原文:http://www.cnblogs.com/lvwei19900624/p/5089397.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!