Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle Listagg function returns null

The good_name column is null for all results.What is problem in the query?

select fp.id,
   listagg(fpg.name, ',') within group(order by fpg.name) good_name
from fp_place_goods fppg join 
   fp_places fp on fppg.place_id = fp.id join
   fp_goods fpg on fppg.good_id = fpg.id
GROUP BY fp.id

however query below works

select fp.id,
   listagg(fpg.id, ',') within group(order by fpg.id) good_ids
from fp_place_goods fppg join 
   fp_places fp on fppg.place_id = fp.id join
   fp_goods fpg on fppg.good_id = fpg.id
GROUP BY fp.id




select fp.id, fpg.name from fp_places fp join
      fp_place_goods fppg on fp.id = fppg.place_id join
      fp_goods fpg on fpg.id = fppg.good_id 

return the result in image

http://i.stack.imgur.com/Y16G3.png

like image 718
Hikmat G. Avatar asked Dec 14 '22 06:12

Hikmat G.


1 Answers

It happened because good_name is nvarchar, and to_char(fpg.name) solved it.

like image 153
Hikmat G. Avatar answered Jan 12 '23 12:01

Hikmat G.