-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,443
  • 5
  • 33
  • 38
Rowling
  • 213
  • 1
  • 8
  • 20

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,242,037
  • 58
  • 646
  • 786