Oracle中将查询出的多条记录的某个字段拼接成一个字符串

SELECT d.relationid ,listagg(to_char(d.starttime,'hh24:Mi')||'-'||to_char(d.endtime,'hh24:Mi')||' 出行方式:'||m.name||',地点:'||d.adress||',详细:'||d.remark ,chr(13)||chr(10))
 within GROUP(order by d.relationid) as tripinfo
 from t_trip_detail d
 left join t_trip_mode m on d.tripmode=m.id
 group by d.relationid

模板:

select 表.ID
       listagg(表.Name, ',') within GROUP(order by 表.Name) as name
  from 表

 group by 表.ID

 

结果为:ID         NAME

             1           xx,xx

             2           xx,xx
 

你可能感兴趣的:(原创)