How to retrieve two columns data in A,B format in Oracle

后端 未结 4 1375
刺人心
刺人心 2020-11-27 23:49

I have two columns in oracle database

+---------+---------+
| Column1 | Column2 |
+---------+---------+
| A       | 1       |
| A       | 2       |
+--------         


        
4条回答
  •  春和景丽
    2020-11-27 23:53

    All abow answers are correct and I want to add one case to solve small problem. In my case my_column1 type was nvarchar2 but text was number and the bellow code does not work and display me only whitespace:

    select group_id, listagg( t.my_column1 || '-' || to_char(t.doc_date,'dd.mm.yyyy') ||  ' ') within group(order by doc_date) 
     from my_table t
     group by group_id
    

    when I wrote like this it works.

    select group_id, listagg( to_char(t.my_column1) || '-' || to_char(t.doc_date,'dd.mm.yyyy') ||  ' ') within group(order by doc_date) 
     from my_table t
     group by group_id
    

    I hope my feedback would save someone's time

提交回复
热议问题