分割字符串问题

上一篇 / 下一篇  2006-09-06 00:00:00 / 个人分类:oracle开发

分割字符串问题!

问题源自http://www.itpub.net/626418.html

/*

怎样支掉字符串中逗号间重复的字符
如 ',1,2,5,9,1,2,5,9,1,2,9,1,2,9,1,2,3,9,1,2,3,9,1,2,9,1,2,9,1,2,3,9,1,2,3,9,'怎样支掉字符串中逗号间重复的字符,并将字符升序排列,得到
',1,2,3,5,9,'
百思不得其解,是高手的试一下。

解答:
select col from(
select sys_connect_by_path(col,',')||',' col,level from(
select col,row_number() over(order by rownum) rn from (
select distinct substr(col,instr(col,',',1,rownum)+1,instr(col,',',1,rownum+1)-instr(col,',',1,rownum)-1) col from (
select ',1,2,5,9,1,2,5,9,1,3,9,' col from dual
) connect by rownum<length(translate(col,','||col,','))
)
)
connect by prior rn = rn -1 order by level desc
) where rownum=1

*/

这个问题的解决办法中的一部分(按照固定分隔符分割字符串)可以解决http://www.itpub.net/515354.html

/*

要求用pl/sql写一个函数, 实现根据分割符把原字符串分成若干个字符串功能.

输入: string(字符串) 和 Delimiter (分隔符)
输出: substr1, ..., substrn (根据分割后的字符串排序, 不是子串在原字符串中的顺序)

解答:

select substr(col,instr(col,',',1,rownum)+1,instr(col,',',1,rownum+1)-instr(col,',',1,rownum)-1) col from (
select ',1,2,5,9,1,2,5,9,1,3,9,' col from dual
) connect by rownum<length(translate(col,','||col,','))

*/



TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-07-26  
  12345
6789101112
13141516171819
20212223242526
2728293031  

数据统计

  • 访问量: 4141
  • 日志数: 1503
  • 建立时间: 2008-04-17
  • 更新时间: 2008-07-22

RSS订阅

Open Toolbar