分割字符串问题! 问题源自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,','))
*/