首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 冲浪宝典 > 网络资源 > Oracle存储过程中去掉重复字符串的函数
【标  题】:Oracle存储过程中去掉重复字符串的函数
【关键字】:Oracle
【来  源】:http://blog.csdn.net/xianbin/archive/2006/11/27/1416611.aspx

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;
Oracle 参数绑定性能实践:【上一篇】
oracle数据库入侵时常用的操作命令:【下一篇】
【相关文章】
  • Oracle 参数绑定性能实践
  • 学生笔记(Oracle第二章)
  • oracle10g在FC6下的安装
  • Oracle 9i 分析函数参考手册(转)
  • ORACLE DBA不定时更新小知识(如有不同请指正)
  • SQL与ORACLE的对比
  • oracle命令
  • oracle常用命令1
  • ubuntu6.06下oracle10g企业版的安装
  • Oracle9iR2 Data Guard的保护模式
  • 【随机文章】
  • RIAWork介绍之二:静态以及动态性质的分离处理
  • 初探软件度量
  • 脱Visual Protect V2.1.0的壳
  • 分盐问题
  • 给FreeBSD新手的一些建议
  • 关于CorelDRAW 节点
  • Apache安装设置
  • Ubuntu下编译声卡驱动
  • 简单的wxWindow程序示例[原转]
  • 狂野西部餐厅
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.