1. 程式人生 > >oracle資料庫把某行資料轉成一列資料

oracle資料庫把某行資料轉成一列資料

select running_time,
       running_user,
       algorithm_id,
       algorithm_list_id,
       name1,
       name2,
       ROWNUM,
       wm_concat(to_char(tag_name)) as tag_name
  from (select s.*, m.tag_name
          from (select t.running_time,
                       t.running_user,
                       t.algorithm_id,
                       t.algorithm_list_id,
                       t.result_file_name,
                       t1.algorithm_name   as name1,
                       t2.algorithm_name   as name2                      
                  from rt_algorithm_run_result t
                  left join rt_algorithm_source t1
                    on t.algorithm_id = t1.algorithm_id
                  left join rt_algorithm_source t2
                    on t.algorithm_list_id = t2.algorithm_id
                 where t2.algorithm_name is not null
                   and t1.algorithm_name is not null) s
          left join rt_algrithmresult_maptag a
            on s.algorithm_id = a.runresult_id
          left join rt_tag m
            on m.tag_level = a.tag_id
         where tag_name is not null) res where ROWNUM between 1 and 30
 group by running_time,
          running_user,
          algorithm_id,
          algorithm_list_id,
          name1,
          name2,
          ROWNUM order by ROWNUM  ASC

在該過程中需要注意的是我們呼叫了oracle資料庫的系統函式wm_connect()函式,但是該函式又要必須呼叫to_char(列名)才能生效