首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

oracle某字段值逗号分隔列转向行实现技巧

2013-01-19 
oracle某字段值逗号分隔列转为行实现技巧select substr(x.col_1, x.pos1, x.pos2 - x.pos1 - 1)from (sele

oracle某字段值逗号分隔列转为行实现技巧
        select substr(x.col_1, x.pos1, x.pos2 - x.pos1 - 1)
          from (select t.col_1,
                        level as lv,
                        instr(',' || t.col_1 || ',', ',', 1, level) as pos1,
                        instr(',' || t.col_1 || ',', ',', 1, level + 1) as pos2
                   from (
                         /**将某字段,由逗行分隔的列值转成行**/
                         select wm_concat(targetCol) col_1  from tableName                       
                         ) t
                 connect by level <= (length(t.col_1) -
                            length(replace(t.col_1, ',', ''))) + 1) x

热点排行