concatination of data in a column into a single row

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bytesshalini
    New Member
    • Oct 2008
    • 4

    concatination of data in a column into a single row

    table contents:
    store_id store_name
    -------- ----------------------
    101 xx
    101 yy
    101 zz
    102 sss
    102 hhh

    I need the following output:

    store_id store_name
    -------- ----------------------
    101 xx, yy, zz
    102 sss, hhh



    i need a simple select query without using procedures, functions
    i have only select privileges
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    what you have tried so far to get the desired output.

    Comment

    • vchandrasekhar
      New Member
      • Oct 2008
      • 1

      #3
      [code=oracle]

      CREATE OR REPLACE FUNCTION rowtocol( p_slct IN VARCHAR2,
      p_dlmtr IN VARCHAR2 DEFAULT ',' ) RETURN VARCHAR2
      AUTHID CURRENT_USER AS
      TYPE c_refcur IS REF CURSOR;
      lc_str VARCHAR2(4000);
      lc_colval VARCHAR2(4000);
      c_dummy c_refcur;
      l number;

      BEGIN

      OPEN c_dummy FOR p_slct;
      LOOP
      FETCH c_dummy INTO lc_colval;
      EXIT WHEN c_dummy%NOTFOUN D;
      lc_str := lc_str || p_dlmtr || lc_colval;
      END LOOP;
      CLOSE c_dummy;

      RETURN SUBSTR(lc_str,2 );


      END;
      /
      [/code]


      use this function and write query in queries to get the required format

      Comment

      Working...