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 Issue

Orcl ApexMay 19 2022

Hi, I have the below query and it return me incorrect result i.e. as below but I need something like in desired result. Can you please help?
What I mean is I need null values as well in between commas.

WITH t AS (
    SELECT NULL c1, 'a' c2
    FROM dual UNION
    SELECT 'b' c1, NULL c2
    FROM dual
  ) SELECT LISTAGG (c1, ',') WITHIN
      GROUP (ORDER BY 1) AS c1
		  , LISTAGG (c2, ',') WITHIN
      GROUP (ORDER BY 1) AS c2
FROM t

Result -

c1 c2
b   a

Desired result - 

c1        c2
null, b   a, null
This post has been answered by mathguy on May 19 2022
Jump to Answer
Comments
Post Details
Added on May 19 2022
5 comments
532 views