How to transpose column into row in oracle sql 11G

前端 未结 2 1166

I need to convert column into row for the below select column_name from all_tab_cols where table_name=\'TABLE_NAME\' ;

COLUMN_1
COLUMN_2
COLUMN_         


        
相关标签:
2条回答
  • 2020-12-22 01:34

    Try this:

    select listagg(A,'  ') within group (order by A) as Names
    from test
    

    In ur case the query goes like:

    select listagg(column_name,'  ')  within group (order by column_name) as column_name
    from all_tab_cols 
    where table_name='TABLE_NAME' ;
    
    0 讨论(0)
  • 2020-12-22 01:53

    after so much time on googling

    i found that pivot query haven't any dynamic features

    so after i found solution at here

    https://technology.amis.nl/2006/05/24/dynamic-sql-pivoting-stealing-antons-thunder/

    here download pivot function from here

    http://paste.ubuntu.com/21378705/

    run this script and this script automatically create pivot function

    with the use of this function we can create dynamic column from rows.

    Example :

        select * from table( pivot(  Q'$ select column_name,column_name name 
        from all_tab_cols where table_name = 'TABLE_NAME' $') )
    

    i hope this will help.

    0 讨论(0)
提交回复
热议问题