Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i think icant explain question header;

i'im getting data from oracle and my data is like this
COL1	COL2
M	1
M	2
O	7
O	8
B	10
B	11
G	15
M	25
O	26


but i want to get this data like this

COL1	COL2
M	M-1/2/25
O	O-7/8/26
B	B-10/11
G	G-15


HOW Can i do this?

What I have tried:

i didnt try anything because
I could not construct
Posted
Updated 29-Oct-20 23:29pm

Your starting point is to understand PIVOT - See Pivot and Unpivot Oracle Database 11g[^] or A Practical Guide to Oracle PIVOT By Real-world Examples[^]
Pivot is common to most T-SQL based RDBMS like Oracle, SQL etc.

However, Oracle also has a built in function that will enable you to do what you want - LISTAGG for Converting Rows to Comma-Separated String - Oratable[^] - just use "/" instead of ","
 
Share this answer
 
i find my solution;

SQL = "select COL1,LISTAGG(COL2, ', ') WITHIN GROUP (ORDER BY COL1) AS NAME " & _
" from  ORACLETABLE  group by COL1 order by COL1 asc"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900