简单行转列

来源:互联网 发布:神之浩劫等待游戏数据 编辑:程序博客网 时间:2024/06/05 06:26

with temp as
 (select t.TEXT as text from T_TEXT_TESTt)

select temp1.text 类型, count(1) 数量
  from (select substr(text,
                      instr(text, ',', 1, rn) + 1,
                      instr(text, ',', 1, rn + 1) - instr(text, ',', 1, rn) - 1) text
       
          from (select ',' || t1.text || ',' text, t2.rn
                  from (select text,
                               length(text) - length(replace(text, ',', '')) + 1 rn
                          from temp) t1,
                       (select rownum rn
                          from all_objects
                         where rownum <=
                               (select max(length(text) -
                                           length(replace(text, ',', '')) + 1) rn
                                  from temp)) t2
                 where t1.rn >= t2.rn
                 order by text, rn)) temp1
 group by temp1.text
union all
select N'空' as 类型, count(*) as 数量
  from T_TEXT_TESTt
 where TEXT is null

0 0
原创粉丝点击