-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
  • 113,669
  • 10
  • 50
  • 103

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,371
  • 1
  • 23
  • 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
  • 6,976
  • 5
  • 30
  • 53
-1

try this

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

Try this:

SELECT GROUP_CONCAT(emp_id) as emp_id FROM employees;
Matt Seymour
  • 8,316
  • 7
  • 56
  • 99
Kishan Reddy
  • 137
  • 4