日期:2014-05-17  浏览次数:20583 次

谁帮忙写一个SQL语句,正则,行转列
表document里的数据:

id    name
1     a
2     b,c
3     a,b,c,d
4     b,c
.      .
.      .
.      .

SQL语句查出的结果
1     a
2     b
2     c
3     a
3     b
3     c
3     d
4     b
4     c


name中的“,”的个数不确定。。。
多谢!
------解决方案--------------------
引用:
Quote: 引用:


select id,distinct regexp_substr(name, '[^,]+',1,level) name
from document
connect by level <= length(name) - length(replace(name,',','')) + 1


distinct缺失表达式,再说  id , name 都是可以重复的


 sorry id是写完后再家的 没注意到 

不管是用上面的 还是用游标循环拆分 大数据的话 效率肯定都不会太快 

如果数据能大到一定程度 那只能说明 这表没设计好