zoukankan      html  css  js  c++  java
  • Oracle 对字符串去重函数

    CREATE OR REPLACE FUNCTION ZZMES."REMOVESAMESTR" (oldStr varchar2, sign varchar2)
    return varchar2 is
    /****************************************************
    ** Copyright (c) 2008,亚科技术开发中心
    ** All rights reserved.
    **
    ** 函数名称:RemoveSameStr
    ** 参 数:【名称】 【类型 】 【说明】
    ** oldStr varchar2 要处理的字符串
    ** sign varchar2 字符串分隔符
    ** 返 回 值:Result varchar2 不包含重复子串的记录
    ** 摘 要:去除字符传中重复的记录
    **
    ** 当前版本:1.0
    **
    ** 作 者:zhangbq
    ** 完成日期:2008年04月09日
    ** 备 注:
    ****************************************************/
    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;
    --字符串太长
    if length(oldStr) > 1000 then
    return(oldStr);
    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 RemoveSameStr;

  • 相关阅读:
    细看JS中的BOM、DOM对象
    IE假死,文本框不能录入div模拟模式对话框释放不干净
    发布一个cmd 设置IP地址的脚本.
    解决一个用Request.Form 取checkbox 取不到值的问题.
    在Global.asax中实现URL 的重写.
    .net 递归生成树,根据编码进行递归.
    发布一篇 DataTable 转化为适合 jquery easyui tree,combotree 的json 函数
    批量插入数据sql
    添加背景音乐由icon控制
    echarts使用macarons主题
  • 原文地址:https://www.cnblogs.com/echo-ling/p/7478965.html
Copyright © 2011-2022 走看看