-3

I'm trying to display all the employee id's

i need the result like

emp_id

10,11,12,13,14,15..,...

when tried

SELECT LISTAGG(emp_id, ',') WITHIN GROUP (ORDER BY emp_id) AS ID FROM employees GROUP BY emp_id;

I'm getting error

ORA-00923: FROM keyword not found where expected

where is the problem here?

MT0
  • 143,790
  • 11
  • 59
  • 117

5 Answers5

1

Use LISTAGG function. Refer here for more in detail. Try like this,

SELECT listagg(emp_id,',') WITHIN GROUP(ORDER BY emp_id) t 
FROM   employees;
Dba
  • 6,511
  • 1
  • 24
  • 33
0

For SQL try

 SELECT GROUP_CONCAT(emp_id) as emp_id FROM employees;

Working demo at http://sqlfiddle.com/#!2/90dd2/1

For Oracle

SELECT LISTAGG(emp_id,',') WITHIN GROUP(ORDER BY emp_id) as emp_id 
FROM   employees;

demo at http://sqlfiddle.com/#!4/af004/9

Deepika Janiyani
  • 1,487
  • 9
  • 17
-1

Try this

SELECT CONCAT(emp_id,',') FROM employees;
Mad Dog Tannen
  • 7,129
  • 5
  • 31
  • 55
-1

try this

 declare @empid nvarchar(500)=''
    select @empid=@empid+Emp_id + ',' from tblemployee
    select substring(@empid,0,len(@empid)-1)
Indranil.Bharambe
  • 1,462
  • 3
  • 14
  • 25
-1

Try this:

SELECT GROUP_CONCAT(emp_id) as emp_id FROM employees;
Matt Seymour
  • 8,880
  • 7
  • 60
  • 101
Kishan Reddy
  • 137
  • 4