中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 数据库开发 > Oracle
Oracle存储过程中去掉重复字符串函数
作者:shangyang 时间:2007-06-15 16:49 出处:ccidnet.com 责编:月夜寒箫
              摘要:Oracle存储过程中去掉重复字符串函数

以下函数是本人在编写Oracle数据库存储过程时写的函数,觉得该函数通用性较强,因此发表出来供需要的人参考。

这个函数的功能主要是用于去除给定字符串中重复的字符串.在使用中需要指定字符串的分隔符.示例:

str := MyReplace('13,14,13,444', ',');

输出:

 

13,14,444
            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;
关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有