Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Listagg returns a null record when no result found

Faezeh EbrahimiJun 9 2024

Here's my query :

SELECT  
max(g.name) as good_name,
max(cp.goods_id) as c5good_id
,listagg(CASE WHEN inf.id IS NULL THEN cp.catalogues_properties_description_id ELSE inf.name END ,'-' ON OVERFLOW TRUNCATE) information
,listagg(attr.name,'-' ON OVERFLOW TRUNCATE) attributes
 
from goods_cp cp 
LEFT JOIN catalogues_properties attr ON cp.catalogues_properties_id=attr.id
LEFT JOIN catalogues_properties inf ON cp.catalogues_properties_description_id = TRIM(to_char(inf.id))
join goods g on g.id = cp.goods_id
where cp.goods_id = 123456  ---no data found for this id

the id that I put for my where clause condition is invalid and the query must no records , but when I use listaggor any aggregation function , it will return 1 null record for me . Why is that happening ?

This post has been answered by Jim Dickson on Jun 9 2024
Jump to Answer
Comments
Post Details
Added on Jun 9 2024
3 comments
2,804 views