LISTAGG in Oracle for joined table and if there is no data in the column.

hi All,
Using LISTAGG i am trying to achieve the below in Oracle.

Billrun    Account
C1         12345
C1
C1         67894
C2         23567
C2
C2         15566

I want to return, if there is no data i need to get and empty space.
C1       12345, ,67894
C2       23567, ,15566

But i am getting always like
C1       12345,67894
C2       23567,15566
Vinoy K PAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jan LouwerensSoftware EngineerCommented:
In your WHERE clause, add: AND Account IS NOT NULL
Jan LouwerensSoftware EngineerCommented:
I may have read that backwards. If you want it the other way around, try: LISTAGG(NVL(TO_CHAR(Account), ' '), ', ') ...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vinoy K PAuthor Commented:
Thanks For the reply
But its making some issue in the order
Table Data
BANGSTESTCASE      DAVID          III
Bangstestcase      Michelle      123

OutPut after Query Execution-  123 is supposed to come after III
DAVID,Michelle      BANGSTESTCASE,Bangstestcase      123, III


Query i am using
SELECT BO.LOAN_ID ,
LISTAGG(BO.BORROWER_FIRST_NAME, ',') WITHIN GROUP (ORDER BY BO.BORROWER_FIRST_NAME) AS FIRST_NAME,
LISTAGG(BO.BORROWER_LAST_NAME, ',') WITHIN GROUP (ORDER BY BO.BORROWER_LAST_NAME) AS LAST_NAME,
LISTAGG(NVL(TO_CHAR(BO.BORROWER_SUFFIX), ' '), ', ') WITHIN GROUP (ORDER BY BO.BORROWER_SUFFIX) AS BORROWER_SUFFIX
FROM   WCTS.BORROWER BO RIGHT OUTER JOIN WCTS.CO_BORROWER COB ON BO.LOAN_ID = COB.LOAN_ID   WHERE BO.LOAN_ID = 1
--AND BO.BORROWER_SUFFIX IS NOT NULL - This wont work because i will loose the entire data if SUFFIX is NULL
GROUP BY BO.LOAN_ID;
Vinoy K PAuthor Commented:
Thanks it works , I Understood that the problem was with my Order By i Changed it to  
order by rownum and all looks good . Thanks for the help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.