Concatenate multiple row values into single column value

Hello,
Can anyone please refresh my memory on how to concatenate multiple row values into a single column value.
In the following query, I will get multiple denial reasons per application and I would rather return all denial reasons on one line.
SELECT a.application_id, a.membership_number,
r.reason_text AS denial_reason,
a.appl_receipt_date AS application_receipt_date,
a.plan_request_1 AS application_plan_code,
a.adjudication_date AS application_denial_date
FROM application a, PLAN p, application_reason ar, reason r
WHERE a.plan_request_1 = p.plan_cd
AND a.application_id = ar.application_id
AND ar.reason_id = r.reason_id
AND a.adjudication_cd = 'D'
AND a.appl_receipt_date BETWEEN '01-jan-2006' AND '31-dec-2006'
AND p.plan_type_id = 12 and a.application_id = :appId
ORDER BY application_id
Any help is greatly appreciated.
Thanks,
-Christine

found the following
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
3 rows selected.at http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php

Similar Messages

  • Concatenate multiple rows in a single column

    Hi 
    I am using Web Intelligence v4.0x (i think) and I am hoping to get help.
    My query (from Performance Management Module) has a field name called "Device Name" and it has two rows, server1 and server 2 (maximum of 33 servers)
    I am trying to concatenate these values so that a blank cell in a report reads
    "Devices are: server1, server2"
    I am not able to concatenate server1 and server2 (i.e. get server1, server2) in the above statement. I've tried to use Previous(Self) and it does not work. I get output in two rows as
    server1,
    server2,
    Any assistance or direction is appreciated.
    Thanks - Kev

    Hi Jothi,
    The solution that helped me earlier
    "VAR1 =Replace(ReportFilter([Customer]);";";",")"
    worked for one Customer ID that had two (or more) invoice# related to that Customer ID.
    If there is more than one customer ID fetched by the query, the above solution merges all the related invoice# in that variable and does not merge invoice# per Customer ID.
    E.g.
    Customer ID     Invoice ID
    0001               P100
    0001               P101
    0002               P150
    0002               P151
    Desired Output
    Customer ID     Invoice ID
    0001               P100, P101
    0002               P150, P151
    Actual Output: The query merges as:
    Customer ID     Invoice ID
    0001               P100, P101, P150, P151
    0002               P100, P101, P150, P151
    and so on till the last customer ID is fetched.
    Is it possible to tweak the query to obtain the Desired Output? Your help is appreciated.
    Thanks - Kavan

  • Concat rows values into single column

    Hi All,
    How can I concat values of a multiple rows into a single column by separating them by comma.
    Eg:
    SELECT empno FROM emp;
    empno
    1
    2
    3
    4
    I want output should be:
    Empnos
    1,2,3,4
    Thanks & Regards,
    Danish

    MichaelS wrote:
    Or
    SQL>  select rtrim(xmlagg(xmlelement(e, empno || ',')).extract('//text()').extract('//text()') ,',') empnos from emp
    EMPNOS                                                                         
    7369,7499,7521,7566,7654,7698,7782,7788,7839,7844,7876,7900,7902,7934 
    Hi Michael,
    is it an error or is it correct to put extract 2 times? This is giving to me the same result:
    select rtrim(xmlagg(xmlelement(e, empno || ',')).extract('//text()'),',') empnos from emp;
    EMPNOS                                                                         
    7369,7499,7521,7566,7654,7698,7782,7788,7839,7844,7876,7900,7902,7934           Regards.
    Al

  • Multiple values into single column

    Hi ,
    Im having the query like as below
    with t as ( select 'Approved' as "Code" from dual union all
    select 'Historically Relevant' from dual union all
    select 'In Progress' from dual union all
    select 'Internal Review' from dual )
    select "Code"  from t  where "Code" in ('Approved,Historically Relevent')
    in this i need the output like below . ie, what are the things i have selected in where clause based on that the output need to come
    'Approved,Historically Relevent'
    Thanks in Advance ...

    Always remember to post your database version as it can make a difference to the answer.
    In 10g you would use sys_connect_by_path to aggregate strings together...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'Approved' as code from dual union all
      2             select 'Historically Relevant' from dual union all
      3             select 'In Progress' from dual union all
      4             select 'Internal Review' from dual )
      5  --
      6  -- end of test data
      7  --
      8  select ltrim(sys_connect_by_path(code,','),',') as codes
      9  from (
    10        select code, rownum r
    11        from t
    12        where code in ('Approved','Historically Relevant')
    13       )
    14  where connect_by_isleaf = 1
    15  connect by r = prior r + 1
    16* start with r = 1
    SQL> /
    CODES
    Approved,Historically Relevant
    In 11gR2 onwards you can use the new LISTAGG function
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'Approved' as code from dual union all
      2             select 'Historically Relevant' from dual union all
      3             select 'In Progress' from dual union all
      4             select 'Internal Review' from dual )
      5  --
      6  -- end of test data
      7  --
      8  select listagg(code,',') within group (order by rownum) as codes
      9  from t
    10* where code in ('Approved','Historically Relevant')
    SQL> /
    CODES
    Approved,Historically Relevant

  • SQL - Multiple rows in a single column

    Hi everyone,
    I have a little question,
    The result of my query looks like this:
    VALOR
    HERRERA
    ANDREW
    CHARLES
    But I need they look like this:
    VALOR
    HERRERA - ANDREW - CHARLES
    How I can do that without using PL/SQL?
    Thanks for the help.

    Hi Justin,
    Thanks for reply. The answer for your questions are:
    1) No, sometimes could be 1 or 2 or 3 or....n
    2) The true is that the result of the query have more columns. Here is the result of the query:
    ID NAME VALUE SEC
         150     ALGOMAS     44 1
         150     AQWER     56456 1
         150     DFDSF     FG345143 1
         150     GFDGDF     5433 1
         150     TEST_123     HERRERA 1
         166     ALGOMAS     22 1
         166     AQWER     33 1
         166     DFDSF     44 1
         166     GFDGDF     55 1
         166     TEST_123     ANDREW 1
         243     ALGOMAS     1 1
         243     AQWER     2 1
         243     DFDSF     3 1
         243     GFDGDF     4 1
         243     TEST_123     WINDSOR 1
         505     ALGOMAS     VALOR DE CARAC 1
         505     AQWER     VALOR DE CARAC 1
         505     DFDSF     DDFDF 1
         505     GFDGDF     DFGG 1
         505     TEST_123     HERRERA 1
         505     TEST_123     CHARLES 2
         505     TEST_123     ANDREW 3
    If you see the three last rows, it repeat the NAME and the ID, What I need is that three records combine in one only row.
    This is really a subquery, only need the VALUE column for the "big query", but when i execute the big query, i got the ORA-01427 error: single-row subquery returns more than one row. I know that error comes out because the NAME = TEST_123 in the ID = 505 have more than one value, so, if there is any way to put that values in only one rows, it resolve my problems.
    3) Oracle Database 10g Release 10.2.0.1.0
    I offer apologies if the initial information was not enough.
    Once again, thanks for reply.
    LCJ.

  • Create a view to shows data from multiple rows in a single column

    Hi all - this is probably posted in the wrong forum but I couldn't find which was the correct one.
    I am almost a complete novice at sql but I have a need to create a view which can be developed at 10g (which runs efficiently as the volumes are likely to be high) which will do the following.
    Original table with columns Parent_code, Child_code
    Parent_Code Child_Code
    1000 2000
    1000 3000
    1000 4000
    2000 3000
    2000 5000
    (note Parents can have multiple children and a child can have multiple parents!)
    What I need to end up with in my view is the following
    Child_Code Parent_List
    2000 '1000 (3)'
    3000 '1000 (3), 2000 (2)'
    4000 '1000 (3)'
    5000 '2000 (2)'
    Note the number in parantheses is the number of children that the parent has - ie in the original table parent 1000 has 3 rows (one for each child)
    This view is then to be used as a look up (on child code) for a business objects report.
    Is there anyone who could PLEASE, PLEASE help me fairly quickly on this as I have very little time to find a solution?

    Hi,
    You can test these ones :
    select child_code
         , ltrim(sys_connect_by_path(parent_info,', '), ', ') as parent_list
    from (
      select child_code
           , to_char(parent_code) ||
             ' (' ||
             count(*) over(partition by parent_code) ||
             ')' as parent_info
           , row_number() over(partition by child_code order by parent_code) rn
      from your_table
    where connect_by_isleaf = 1
    connect by prior rn = rn-1
           and prior child_code = child_code
    start with rn = 1
    select child_code,
           rtrim(
             extract(
               xmlagg(xmlelement("e",parent_info||', ') order by parent_info)
             , '//text()'
           ) as parent_list
    from (
      select child_code,
             to_char(parent_code) ||
             ' (' ||
             count(*) over(partition by parent_code) ||
             ')' as parent_info
      from your_table
    group by child_code
    ;What you need is called "string aggregation".
    See here for various techniques, including the two above : http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php

  • How to display the multiple rows in a single column ?

    Hi,
    I have the Query like this :
    SELECT MS.SUBJECT, MS.MESSAGEDESC, MS.MSGDATE, MAT.ATTACHMENT
    FROM MESSAGES MS, MSESAGEATTACHEMTASSO MAA, (select pga.programid,
    act.accountname,
    row_number() over(partition by pga.programid order by act.accountname) rn
    from accounttypes act, programpursesasso pga
    where act.accounttypeid = pga.accounttypeid ) MSGATTACHMENTS
    WHERE MS.MESSAGEID = MAA.MESSAGEID
    AND MAA.MSGATTACHMENTID = MAT.MSGATTACHMENTID
    AND MS.MESSAGEID = 1;
    If i have multiple messageAttachments for single message ., i want to display them in a single row.,
    like :
    subject messagedesc msgdate attachment1 attachment2 .....attachmentn
    test test 10/10/2007 test test test
    can any one help me out ., how can i do this using simple sql query ?

    Hi,
    Thanks for the Reply .,
    I have the 2 table like :
    DESC MESSAGES;
    Name Type Nullable Default Comments
    MESSAGEID NUMBER(16)
    EMAILFROM VARCHAR2(50) Y
    EMAILTO VARCHAR2(50) Y
    SUBJECT VARCHAR2(500) Y
    MESSAGEDESC VARCHAR2(2000) Y
    MSGDATE DATE Y
    MSGSTATUS NUMBER(1) Y
    MSGDELETESTATUS NUMBER(1) Y
    SQL> DESC MESSAGES;
    Name Type Nullable Default Comments
    MESSAGEID NUMBER(16)
    EMAILFROM VARCHAR2(50) Y
    EMAILTO VARCHAR2(50) Y
    SUBJECT VARCHAR2(500) Y
    MESSAGEDESC VARCHAR2(2000) Y
    MSGDATE DATE Y
    MSGSTATUS NUMBER(1) Y
    MSGDELETESTATUS NUMBER(1) Y
    SQL> DESC MSGATTACHMENTS;
    Name Type Nullable Default Comments
    MSGATTACHMENTID NUMBER(16)
    ATTACHMENT CLOB
    ATTACHMENTDATE DATE Y
    SQL> DESC MSESAGEATTACHEMTASSO;
    Name Type Nullable Default Comments
    MSGATTCHID NUMBER(16)
    MESSAGEID NUMBER(16) Y
    MSGATTACHMENTID NUMBER(16) Y
    What I need Is :
    If One Msg is having multiple attachement , then i want to display all the attachment in a single row along with MsgSubject, MsgDate, MsgDesc like
    I want to dipaly the MsgSubject, MsgDesc, MsgDate, Attachment1
    MsgSubject MsgDate Msgdesc Attachment1 Attachment2 Attachment3 ...etc

  • Multiple rows in a single column in a SQL statement

    Can anyone provide me with a simple sql which will run on the below table (USERROLE table)
    ID ROLEUSER ROLENAME
    1 user1 GL
    2 user2 OBI_AP
    3 user1 OBI_AP
    4 user2 GL
    5 user1 OBI_AR
    6 user2 AR
    7 user3 GL
    and give the result as
    ROLEUSER ROLENAMES
    user1 GL;OBI_AP;OBI_AR
    user2 OBI_AP;GL;AR
    user3 GL
    Thanks
    Vikram

    In 10g,
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Elapsed: 00:00:01.12
    satyaki>
    satyaki>
    satyaki>with t2
      2  as
      3    (
      4      select 1 id, 'user1' ROLEUSER, 'GL' ROLENAME  from dual
      5      union all
      6      select 2, 'user2', 'OBI_AP' from dual
      7      union all
      8      select 3, 'user1', 'OBI_AP' from dual
      9      union all
    10      select 4, 'user2', 'GL' from dual
    11      union all
    12      select 5, 'user1', 'OBI_AR' from dual
    13      union all
    14      select 6, 'user2', 'AR' from dual
    15      union all
    16      select 7, 'user3', 'GL' from dual
    17    )
    18  select ROLEUSER ,
    19         substr( string, 2 ) as string
    20  from dual
    21  where 1 = 2
    22   model
    23     reference t_ref
    24     on
    25      (
    26          select row_number() over ( order by id ) - 1 as row_num ,
    27                 count(*) over () - 1 as max_row_num ,
    28                 ROLEUSER ,
    29                 ROLENAME
    30          from t2
    31          where ROLENAME is not null
    32          order by ROLENAME
    33     )
    34    dimension by( row_num )
    35    measures ( max_row_num, ROLEUSER, ROLENAME )
    36    main t_main
    37    dimension by ( cast( null as varchar2(4000) ) as ROLEUSER )
    38    measures ( cast( null as varchar2(4000) ) as string )
    39     rules
    40     iterate( 4294967295 )
    41     until
    42       (
    43          t_ref.max_row_num[0] is null or
    44          iteration_number >= t_ref.max_row_num[0]
    45       )
    46       (
    47          string[ t_ref.ROLEUSER[iteration_number] ] = string[ cv() ] || ';' ||
    48          t_ref.ROLENAME[ iteration_number ]
    49       )
    50  order by 1;
    ROLEUSER               STRING
    user1                       GL;OBI_AP;OBI_AR
    user2                       OBI_AP;GL;AR
    user3                       GL
    Elapsed: 00:00:00.26
    satyaki>Regards.
    Satyaki De.

  • Concatenate multiple rows into single row

    Hi I need to concatenate multiple rows,
    these are the rows I have
    Name
    Rnk
    Northshore
    1
    F3
    2
    Borderline
    3
    Mattoon
    3
    Vinemane
    5
    Arizona
    5
    WestShore
    5
    Schumburg
    5
    Wilson
    5
    This is how I would like it to look
    Name
    Rnk
    Northshore
    1
    F3
    2
    Borderline,   Mattoon
    3
    Vinemane,   Arizona, WestShore, Schumburg, Wilson
    5
    Thanks
    LISA86

    I meant is there a way to do it without using a table?
    LISA86
    We have not used any extra table. Ok, Try the below:
    Select distinct
    names= REPLACE(
    Select a.Name as [data()]
    From YOURTABLENAME A
    Where A.Rnk = b.Rnk
    Order by a.Name
    FOR XML PATH ('') ), ' ', ',') ,Rnk
    From YOURTABLENAME B Order by Rnk

  • Merge multiple columns into single column?

    Hi,
    I need to execute queries dynamically and return the values. I need to fetch the values of the queries in single column only by concatenating the multiple columns. I cannot use PL/SQL in my scenario.
    is there any way to execute a query and the result will be fetched in single column (values of multiple columns needs to be concatenated)?
    Thanks,
    Raja.

    hi,
    do you mean this??
      1* select EMPNO||' '||ENAME||' '||JOB||' '||MGR||' '||HIREDATE||' '||SAL||' '||COMM||' '||DEPTNO||
    SQL> /
    MULTIPLE_COL
    100 JDF DIR  05-SEP-09 200 1000 10
    7497 MILLER CLERK 7782 23-JAN-82 25000 195 35
    7566 JONES MANAGER 7839 02-APR-81 3175 446.25 20
    7654 RAR SALESMAN 7698 28-SEP-81 1450 1587.5 30
    7698 BLAKE MANAGER 7839 01-MAY-81 3050 427.5 30
    7782 CLARK MANAGER 7839 09-JUN-81 2650 367.5 10
    7788 SCOTT ANALYST 7566 09-DEC-82 3200 450 20
    7839 KING PRESIDENT  17-NOV-81 5200 8250 10
    7844 TURNER SALESMAN 7698 08-SEP-81 1700 225 30
    7876 ADAMS CLERK 7788 12-JAN-83 1300 165 20
    7900 JAMES CLERK 7698 03-DEC-81 1150 85.5 30 [email protected]
    MULTIPLE_COL
    7902 FORD ANALYST 7566 03-DEC-81 3200 450 20
    8000 KINGBABA PRESIDENT  17-NOV-81 5200 8250 10
    8001 TURNER RAV SALESMAN 8000 08-SEP-81 1700 450 30
    1001 KITTU DOR  05-SEP-09 1200 100 40
    15 rows selected.Or
    Mean this??
    SQL> ed
    Wrote file afiedt.buf
      1  With T As
      2     ( Select Level col1 From dual Connect By Level<=10
      3     )
      4     Select Max(SYS_CONNECT_BY_PATH(COL1||',',' ')) Multi_col
      5       From
      6     ( Select COL1, Lag(COL1) Over (Order By COL1) As Lag
      7             From   T  )
      8      Start With Lag Is Null
      9        Connect By
    10*    Prior col1 = LAG
    SQL> /
    MULTI_COL
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10,Edited by: user291283 on Sep 8, 2009 10:10 PM

  • Join all rows bases on one column value

    Hi All,
    I have requrement like Join all rows bases on one column value, i am not getting how to accomplish that. Here is my requrement. i have table test(id,id_desc) with no key
    table:Test
    id id_desc
    1 desc_a
    1 desc_b
    1 desc_c
    Now the requremnet i have one more table as test1(id,id_desc) here id is primary key. where record i need to insert as
    id id_desc
    1 desc_a
    desc_b
    desc_c

    orza wrote:
    Hi All,
    I have requrement like Join all rows bases on one column value, i am not getting how to accomplish that. Here is my requrement. i have table test(id,id_desc) with no key
    table:Test
    id id_desc
    1 desc_a
    1 desc_b
    1 desc_c
    Now the requremnet i have one more table as test1(id,id_desc) here id is primary key. where record i need to insert as
    id id_desc
    1 desc_a
    desc_b
    desc_cI'm guessing you want to pivot the results in TEST and use that to insert into TEST1?
    If so this may be useful
    http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php

  • How to insert an upper value into a column?

    Hi!,
    I need to insert an upper value into a column.
    The data is on a flat file and it could be lowercase or uppercase?
    Do I have to create a trigger to solve this problem?
    How could the trigger be?
    Thanks,
    Alex

    If you are using SQL*Loader to load the data from flat file into the db table, then you can achieve inserting the UPPER Case of column value in your sqlloader ctl file itself as in below example
    LOAD DATA
    INFILE *
    APPEND INTO TABLE XXX
    ( field1 position(1:7) char "UPPER(:field1)",
    field2 position(8:15) char "UPPER(:field2)"
    BEGINDATA
    Phil Locke
    Jason Durbin
    So in this case the Names Phil Locke and Jason Durbin will be inserted as PHIL LOCKE and JASON DURBIN into the target table.
    Regards,
    Murali Mohan

  • How to copy one column BLOB value into another column of another database.

    How to copy one column BLOB value into another column of another database.
    BLOB value contains word document.
    I thought of copy the BLOB value into a text file and then update the new column value by the same text in textfile. Will this work?
    Is there any other better way to do this?

    You're welcome
    BLOB fields contains binary data. I don't think you can do this
    Also if I view the BLOB as text. Can I copy it and insert into the new database.
    I think your options are as I said. Datapump or CTAS
    Best Regards

  • To populate values into single field in an internal table

    Hi Friends,
    How we need to populate values into single field in an internal table.
    E.g itab consits of single field ( name)
           i need to assign values to this field name .like
          peter,
          john,
          abrahm,
          daneyal
    Pls tell me i how i need to code for this
    Thanks ,
    Parnith

    Hi,
    Please look at the below code :
    DATA : BEGIN OF itab OCCURS 0 ,
             name(20) TYPE c,
           END OF itab.
    START-OF-SELECTION.
      itab-name = 'Peter'.
      APPEND itab.
      CLEAR itab.
      itab-name = 'John'.
      APPEND itab.
      CLEAR itab.
      itab-name = 'Abrahm'.
      APPEND itab.
      CLEAR itab.
      itab-name = 'Daneyal'.
      APPEND itab.
      CLEAR itab.
      LOOP AT itab.
        WRITE : / itab.
      ENDLOOP.
    Thanks,
    Sriram Ponna.

  • Concatenate multiple pdf files into one single postscript file

    Hi,
    Could anyone help me with a code to "Concatenate Multiple pdf files into one single postscript file" ?
    Thanks for the help

    Thanks for your reply! Actually the main purpose is to allow user to select multiple pdf documents on a single web page and then he should be able to print all of them at once by hitting the print button on the web page instead of selecting each document seperately to print it. Also he should be able to see all the printing services available to print those documents.
    Thanks,

Maybe you are looking for