-3

I am using PL/SQL, and I have a very simple query:

select
t.dispatch_date,
t.route,
t.employee_name
from 
dispatch t
where
t.dispatch_date=trunc(sysdate)

However, the result will give me some data like below, because there can be multiple people are assigned in same route: (But I want to combine the name together with ||)

enter image description here

Is there any function I can use to achieve my goal?

Thanks

Aleksej
  • 22,381
  • 5
  • 31
  • 37
Rowling
  • 203
  • 7
  • 19

1 Answers1

1

You are looking for listagg():

select t.dispatch_date, t.route,
       listagg(t.employee_name, '||') within group (order by t.employee_name) as employee_names
from dispatch t
where t.dispatch_date = trunc(sysdate);
Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709