0

I'm learning oracle sql.

I'm just trying to display all the employees first name from 'Employee' table in single line with comma separation.

ex: john,alex,rosy

I'm using SQL*Plus for running the query.

Ramya jois
  • 29
  • 5
  • Did you check this site?, this has more details on writing query to concatenate the rows. https://oracle-base.com/articles/misc/string-aggregation-techniques – Abhilash R Vankayala Feb 17 '17 at 06:26
  • Possible duplicate of [How can I combine multiple rows into a comma-delimited list in Oracle?](http://stackoverflow.com/questions/468990/how-can-i-combine-multiple-rows-into-a-comma-delimited-list-in-oracle) – Aleksej Feb 17 '17 at 08:22

2 Answers2

0

You have to use some built in function like:

SYS_CONNECT_BY_PATH , ROW_NUMBER () OVER 

Here is the solution

Community
  • 1
  • 1
0
SQL> 
SQL> create table test(id int, name varchar(10));
Table created
SQL> begin
  2      insert into test values(1,'john');
  3      insert into test values(2,'alex');
  4      insert into test values(3,'rosy');
  5  end;
  6  /
PL/SQL procedure successfully completed
SQL> select listagg(name ,',')  within group(order by id) result from test;
RESULT
--------------------------------------------------------------------------------
john,alex,rosy
SQL> drop table test purge;
Table dropped

SQL>