DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: multiple row into single row

  1. #1
    Join Date
    Jul 2000
    Location
    india
    Posts
    213
    hi everybody,

    i have a table in which there are say n no of rows..now i want to concate that rows into a single row..for e.g

    SQL> select mailmessage from tempinsert;

    MAILMESSAGE
    ------------------------------------------------------------------
    1,I101,,,
    2,i102,,,

    now i want the o/p as

    1,I101,,, 2,i102,,,
    as a single row as output...how do i do this...pls help

    thanks in advance
    pras

  2. #2
    Join Date
    Apr 2002
    Location
    Philippines
    Posts
    77
    Hi!

    I think you have to do it in PL/SQL, create a function which concatenate the columns somewhat like (not tested) :

    create function concat_this
    as
    v_concat varchar2(2000);
    begin
    for rec in (select col1 from tablename)
    loop
    v_concat := v_concat||rec.col1;
    end loop;
    return v_concat;
    end;


    hth.

  3. #3
    Join Date
    Mar 2001
    Location
    Reading, U.K
    Posts
    598
    SYntax was incorrect:
    this was missing "return varchar2"

    create function concat_this return varchar2
    as
    v_concat varchar2(2000);
    begin
    for rec in (select ename from emp)
    loop
    v_concat := v_concat||rec.ename;
    end loop;
    return v_concat;
    end;
    Cheers!
    OraKid.

  4. #4
    Join Date
    Apr 2002
    Posts
    135

    you can use coalesce function if you use Oracle9i.
    select coalesce(columnname||',' , '') from table

    I have heard of TABLE_TO_COMMA package .
    But i haven't tried it.
    Have a look on it.
    Good Judgement comes from Experience.
    Experience comes from Bad Judgement

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width