代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
PLSQL
】
Oracle 去掉重复字符串
作者:
Dezai.CN
/ 发布于
2012/3/13
/
999
<ol> <li><span><span class="keyword">create</span><span> </span><span class="op">or</span><span> </span><span class="func">replace</span><span> </span><span class="keyword">function</span><span> remove_rame_string(oldStr varchar2, sign varchar2) </span></span></li> <li><span> <span class="keyword">return</span><span> varchar2 </span><span class="keyword">is</span><span> </span></span></li> <li><span> </span></li> <li><span> /**************************************************** </span></li> <li><span> ** Oracle去掉重复字符串 </span></li> <li><span> ** 函数名称:RemoveSameStr </span></li> <li><span> ** 参 数:【名称】 【类型 】 【说明】 </span></li> <li><span> ** oldStr varchar2 要处理的字符串 </span></li> <li><span> ** sign varchar2 字符串分隔符 </span></li> <li><span> ** 返 回 值:Result varchar2 不包含重复子串的记录 </span></li> <li><span> ****************************************************/ </span></li> <li><span> str varchar2(2000); </span></li> <li><span> currentIndex number; </span></li> <li><span> startIndex number; </span></li> <li><span> endIndex number; </span></li> <li><span> </span></li> <li><span> type str_type <span class="keyword">is</span><span> </span><span class="keyword">table</span><span> </span><span class="keyword">of</span><span> varchar2(30) </span><span class="keyword">index</span><span> </span><span class="keyword">by</span><span> binary_integer; </span></span></li> <li><span> arr str_type; </span></li> <li><span> Result varchar2(1000); </span></li> <li><span><span class="keyword">begin</span><span> </span></span></li> <li><span> <span class="comment">-- 空字符串</span><span> </span></span></li> <li><span> if oldStr <span class="keyword">is</span><span> </span><span class="op">null</span><span> </span><span class="keyword">then</span><span> </span></span></li> <li><span> <span class="keyword">return</span><span>(</span><span class="string">''</span><span>); </span></span></li> <li><span> <span class="keyword">end</span><span> if; </span></span></li> <li><span> </span></li> <li><span> <span class="comment">--字符串太长</span><span> </span></span></li> <li><span> if length(oldStr) > 2000 <span class="keyword">then</span><span> </span></span></li> <li><span> <span class="keyword">return</span><span>(oldStr); </span></span></li> <li><span> <span class="keyword">end</span><span> if; </span></span></li> <li><span> str := oldStr; </span></li> <li><span> </span></li> <li><span> currentIndex := 0; </span></li> <li><span> startIndex := 0; </span></li> <li><span> </span></li> <li><span> loop </span></li> <li><span> currentIndex := currentIndex + 1; </span></li> <li><span> endIndex := instr(str, sign, 1, currentIndex); </span></li> <li><span> if (endIndex <= 0) <span class="keyword">then</span><span> </span></span></li> <li><span> exit; </span></li> <li><span> <span class="keyword">end</span><span> if; </span></span></li> <li><span> </span></li> <li><span> arr(currentIndex) := trim(substr(str, </span></li> <li><span> startIndex + 1, </span></li> <li><span> endIndex - startIndex - 1)); </span></li> <li><span> startIndex := endIndex; </span></li> <li><span> <span class="keyword">end</span><span> loop; </span></span></li> <li><span> </span></li> <li><span> <span class="comment">--取最后一个字符串:</span><span> </span></span></li> <li><span> arr(currentIndex) := substr(str, startIndex + 1, length(str)); </span></li> <li><span> </span></li> <li><span> <span class="comment">--去掉重复出现的字符串:</span><span> </span></span></li> <li><span> <span class="keyword">for</span><span> i </span><span class="op">in</span><span> 1 .. currentIndex - 1 loop </span></span></li> <li><span> <span class="keyword">for</span><span> j </span><span class="op">in</span><span> i + 1 .. currentIndex loop </span></span></li> <li><span> if arr(i) = arr(j) <span class="keyword">then</span><span> </span></span></li> <li><span> arr(j) := <span class="string">''</span><span>; </span></span></li> <li><span> <span class="keyword">end</span><span> if; </span></span></li> <li><span> <span class="keyword">end</span><span> loop; </span></span></li> <li><span> <span class="keyword">end</span><span> loop; </span></span></li> <li><span> </span></li> <li><span> str := <span class="string">''</span><span>; </span></span></li> <li><span> <span class="keyword">for</span><span> i </span><span class="op">in</span><span> 1 .. currentIndex loop </span></span></li> <li><span> if arr(i) <span class="keyword">is</span><span> </span><span class="op">not</span><span> </span><span class="op">null</span><span> </span><span class="keyword">then</span><span> </span></span></li> <li><span> str := str || sign || arr(i); </span></li> <li><span> <span class="comment">--数组置空:</span><span> </span></span></li> <li><span> arr(i) := <span class="string">''</span><span>; </span></span></li> <li><span> <span class="keyword">end</span><span> if; </span></span></li> <li><span> <span class="keyword">end</span><span> loop; </span></span></li> <li><span> </span></li> <li><span> <span class="comment">--去掉前面的标识符:</span><span> </span></span></li> <li><span> Result := substr(str, 2, length(str)); </span></li> <li><span> </span></li> <li><span> <span class="keyword">return</span><span>(Result); </span></span></li> <li><span><span class="keyword">end</span><span> remove_rame_string; </span></span></li> </ol>
试试其它关键字
去掉重复字符串
同语言下
.
查看某张表的表结构
.
oracle 集合操作
.
for 循环中倒序 用reverse
.
Oracle 临时表空间收缩
.
查看session及其对应运行的sql
.
Oracle常用查看表结构命令
.
Oracle Connect By Prior用法(实现递归查询)
.
重置排序 SEQUENCE
.
创建一个trigger
.
批量替换字段中的字符
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3