Thursday, July 31, 2014

Sql to convert Rows to a single column seperated with comma (,)

Following SQL shows how to convert multiple row output of a column and print all the output in a single column and values separated with a comma (,).

For real time example we took data on GL Journal Lines:

   SELECT RTRIM (XMLAGG (XMLELEMENT (e, segment1 || ',')).EXTRACT
                                                                   ('//text()'),
                       ','
                      ) segment1
           INTO l_company
           FROM (SELECT DISTINCT segment1
                            FROM gl_je_lines gjl,
                                 gl_code_combinations_kfv gcc
                           WHERE 1 = 1
                             AND gjl.code_combination_id =
                                                       gcc.code_combination_id
                             AND gjl.je_header_id = :l_je_header_id);

No comments: