Solved

Repeat Group Columns

Posted on 2010-11-16
8
580 Views
Last Modified: 2012-05-10
My request is straight forward, I wan to turn multiple rows into one row with multiple columns in oracle sql.
0
Comment
Question by:Roberto Madro R.
  • 4
  • 3
8 Comments
 
LVL 14

Expert Comment

by:ajexpert
ID: 34149965
Can you show us the sample output?
0
 

Author Comment

by:Roberto Madro R.
ID: 34150052
Sorry, I have no ouput, and no script generated yet, I'd like to see how you'd approach such request, here's the basics;

That's what I get now.

Unit, Test Type, Test Results

AA, AGN1, 11
AA, XZf2, 13.5
AA, ADGv, 17

I don't care for the "Test Type, I just want the "Unit" and "Test Results" to come out as follows;

AA, 11, 13.5, 17, ..
0
 
LVL 3

Expert Comment

by:mpaladugu
ID: 34150292
select column_name||column_name2||column_name3 column_alias from table name
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:mpaladugu
ID: 34150315
sorry that is wrong..ignore the above comment
0
 
LVL 3

Expert Comment

by:mpaladugu
ID: 34150458
http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php

above link has a direct answer to your question
0
 
LVL 3

Accepted Solution

by:
mpaladugu earned 500 total points
ID: 34150632
If you are using 10g, then this should do the trick without using pl/sql function,

copied from the link posted above...
Base Data:

    DEPTNO ENAME
---------- ----------
        20 SMITH
        30 ALLEN
        30 WARD
        20 JONES
        30 MARTIN
        30 BLAKE
        10 CLARK
        20 SCOTT
        10 KING
        30 TURNER
        20 ADAMS
        30 JAMES
        20 FORD
        10 MILLER

SELECT deptno,
       LTRIM(MAX(SYS_CONNECT_BY_PATH(ename,','))
       KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
FROM   (SELECT deptno,
               ename,
               ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) AS curr,
               ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) -1 AS prev
        FROM   emp)
GROUP BY deptno
CONNECT BY prev = PRIOR curr AND deptno = PRIOR deptno
START WITH curr = 1;

    DEPTNO EMPLOYEES
---------- --------------------------------------------------
        10 CLARK,KING,MILLER
        20 ADAMS,FORD,JONES,SCOTT,SMITH
        30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
0
 

Author Comment

by:Roberto Madro R.
ID: 34250851
I thought I closed this string not due to any specific solution but rather to the deep insights provided by couple of members on this forum, I'm appreciative and thankful for their input, programmers in every field don't necessarily copy other people's ideas but other people's ideas usually inspire them to code differently thus getting the result they want. That's what happened in this case.

Many Thanks
0
 

Author Closing Comment

by:Roberto Madro R.
ID: 34250855
.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MULTIPLE DATE QUERY 15 103
Deleting Rows from an Oracle Database - Performance 19 76
Database Design Dilemma 6 66
Oracle Errors 11 53
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question