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; 
 

转载于:https://www.cnblogs.com/encounter/archive/2008/01/30/2189176.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/380183.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

基于RBAC模型的通用企业权限管理系统

1. 为什么我们需要基于RBAC模型的通用企业权限管理系统 管理信息系统是一个复杂的人机交互系统&#xff0c;其中每个具体环节都可能受到安全威胁。构建强健的权限管理系统&#xff0c;保证管理信息系统的安全性是十分重要的。权限管理系统是管理信息系统中代码重用性最高的模块…

面向对象 抽象(abstract)

面向对象 抽象&#xff08;abstract&#xff09; 抽象类的概述 A:抽象类概述 抽象就是看不懂的 B:抽象类特点 a:抽象类和抽象方法必须用abstract关键字修饰 abstract class 类名 {}public abstract void eat();b:抽象类不一定有抽象方法&#xff0c;有抽象方法的类一定是抽…

密码学加密算法分类_密码学中的国际数据加密算法(IDEA)

密码学加密算法分类Introduction 介绍 International Data Encryption Algorithm (IDEA) is a type of cryptography as a block cipher algorithm designed by "Xuejia Lai" and "James L.Massey" of ETH-Zrich and was first published in the 1991 yea…

如何定位溢出点位置

程序&#xff1a; #include <stdio.h> void exploit() {system("/bin/sh"); } void func() {char str[20];read(0,str,50);printf("the str is:%s\n",str); } int main() {func();return 0; }关掉保护机制&#xff1a; gcc -no-pie -fno-stack-pro…

.net知识和学习方法系列(六)关于数值类型

过年总是忙&#xff0c;没有更多的时间来写博客&#xff0c;不过还是挺想念这块地方的。 本次博客说一下数值类型吧&#xff01; 不管那种语言&#xff0c;都为数据类型一说&#xff0c;在C#中也是&#xff0c;不过C#的数据类型分了两类&#xff0c;一是值类型&#xff0c;一是…

【竞赛题解】2021年广东工业大学第十五届文远知行杯程序设计竞赛(同步赛)

B 找山坡 题意&#xff1a;在数组中找到两相等元素相距最大的距离且这两元素间的元素都不小于该两端值 思路&#xff1a;采用单调栈 例如&#xff1a;a[] { 2 3 5 4 6 3 }&#xff0c;栈内存储元素的坐标&#xff08;从1开始&#xff09;&#xff0c;便于计算距离 首先将a[…

[转]JAVA AES 加密算法

本文转自&#xff1a;http://blog.sina.com.cn/s/blog_7c8eb1590100svr0.html package com.siro.tools;import javax.crypto.Cipher;import javax.crypto.spec.IvParameterSpec;import javax.crypto.spec.SecretKeySpec;import sun.misc.BASE64Decoder;import sun.misc.BASE64E…

java中Scanner类中 next()与nextLine()的区别

问题&#xff1a;提示用户输入一个英文字符串或者要解密的字符串&#xff0c;然后通过扫描仪获取用户输入的字符串&#xff0c;经过加密或者解密后&#xff0c;把字符串输出。 import java.util.Scanner;public class Encryption {public static void main(String[] args) {Sca…

操作系统中的处理机调度调度_操作系统中的流程分类和调度

操作系统中的处理机调度调度处理 (Process) In the operating system, there are numerous task and application program run simultaneously. A program is stored in the hard disk or any other form of secondary storage. When the program is executed it must be loade…

NX机制及绕过策略-ret2libc

程序&#xff1a; 1.c #include <stdio.h> void exploit() {system("/bin/sh"); } void func() {char str[0x20];read(0,str,0x50); } int main() {func();return 0; }0x01 NX介绍 溢出攻击的本质在于冯诺依曼计算机模型对数据和代码没有明确区分这一先天性缺…

网站SEO策略的制定

在对一个网站做SEO的时候&#xff0c;SEO技术水平类似的人&#xff0c;营销效果可能天壤之别&#xff0c;这是因为网站SEO策略的制定的不同&#xff01;-----这个是最根本的。 SEO技术非常的简单&#xff0c;因为SEO不是去寻找搜索引擎的漏洞&#xff0c;而是根据搜索引…

Python | 程序从列表中删除范围内的所有元素

Given a list and we have to remove elements in a range from the list in Python. 给定一个列表&#xff0c;我们必须从Python中的列表中删除范围内的元素。 删除列表(开始索引&#xff0c;结束索引) (del list(start_index, end_index)) del() method is used to remove a…

面向对象 (接口 Interface)

1&#xff0c;面向对象(接口的概述及其特点) A:接口概述 从狭义的角度讲就是指java中的interface从广义的角度讲对外提供规则的都是接口 B:接口特点 a:接口用关键字interface表示 interface 接口名 {}b:类实现接口用implements表示 class 类名 implements 接口名 {}c:接口…

android unbound prefix

少一个命名空间加上就行了&#xff1a;xmlns:android"http://schemas.android.com/apk/res/android" 转载于:https://www.cnblogs.com/nizuimeiabc1/archive/2011/10/09/4254310.html

【竞赛题解】第22次CCF计算机软件能力认证 B

今天&#xff08;准确说是昨天&#xff0c;一下子就过12点了&#xff09;下午刚参加了CSP认证考试&#xff0c;大概是考了220&#xff08;前两题AC&#xff0c;第三题太折磨了懒得看了&#xff0c;后面两题各混了10分&#xff09;&#xff0c;唯一有点参与感的就是B题了&#x…

gbd调试64位程序关键

程序&#xff1a; 4.c&#xff1a; #include<stdio.h> void exploit() {system("/bin/sh"); } void main() {char buf[20];gets(buf); }编译&#xff1a; gcc -no-pie -fno-stack-protector -m64 -o 4.exe 4.cNX保护&#xff0c;栈数据不可执行 使用命令&…

C#全局鼠标键盘Hook (备查)

using System; using System.Collections.Generic; using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; namespace DCIEngine.FrameWork.Snap { /// <summary> /// 这个类可以让你得到一个在…

fcfs调度算法_FCFS:先来先服务调度算法

fcfs调度算法The FCFS, which stands for First Come First Serve Scheduling Algorithm, is a non-preemptive scheduling algorithm, which means that if a process once starts executing in the processor, then it cannot be preempted in between the processing. Thus,…

亲和数

Problem Description 古希腊数学家毕达哥拉斯在自然数研究中发现&#xff0c;220的所有真约数(即不是自身的约数)之和为&#xff1a; 1245101120224455110&#xff1d;284。 1* 220220&#xff1b;2* 110220&#xff1b;4* 55220&#xff1b;5* 44220&#xff1b;10*20220;…

转:JNI jstring与c++字符串类型转换函数

jstring与c字符串类型转换函数 jstring str2jstring(JNIEnv* env,const char* pat) {//定义java String类 strClassjclass strClass (env)->FindClass("Ljava/lang/String;");//获取String(byte[],String)的构造器,用于将本地byte[]数组转换为一个新Stringjmetho…