各位大侠帮帮我.我现在有一个多列数据结果
NAME P001          P002      P003        P004 P005 P006   ...N
东坡区 7398027.4 62     82730.1945   1115297.2055 0 0 0      ...
仁寿 8734639.99      6208003.602   2526636.388 0 0 0      ...我想把结果转换成行记录NAME     P_t      value   
东坡区   P002   7398027.4
东坡区   P003   82730.1945
东坡区   P004   1115297.2055
东坡区   P005   0
东坡区   P006   0
....N
帮帮忙.......在线急等.

解决方案 »

  1.   


    case when 这个可以吗? 每个字段的值是未知的.
    在具体一点可以吗?
      

  2.   

    列转行要用union all
    select name,'P001' p_t,p001 value from tt union all
    select name,'P002' p_t,p002 value from tt union all
    select name,'P003' p_t,p003 value from tt union all
    select name,'P004' p_t,p004 value from tt union all
    ......
    select name,'P00N' p_t,p00n value from tt
      

  3.   

    用union all解决比较少的字段可以,但是这么多的字段,不仅写的麻烦而且性能不见得好,尝试用procedure吧/
      

  4.   

    select NAME, 
    case l when 1 then 'P001'  when 2 then         'P002'when 3 then     'P003'when 4 then        'P004'when 5 then  'P005' when 6 then  P006 end pt,case l when 1 then P001  when 2 then         P002 when 3 then     P003 when 4 then        P004 when 5 then  P005 when 6 then  P006 end v from a,
    (select level l from dual connect by level<=6) b;
      

  5.   

    用这个就不错
    http://www.akadia.com/services/ora_pipe_functions.html