remove spaces

how do I remove spaces and extra commas from the product_id string? When the value for product_id is null, I get a space and an extra comma.

user_id      product_id
12345       AA, BB, CC, , EE, , ,

SELECT user_id,
AA||', '||BB||', '||CC||', '||DD||', '||EE||', '||FF||', '||GG product_id
 FROM  table
Who is Participating?
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.

replace(replace(col_name, CHR(13), ''), CHR(10), '')

WITH t AS (SELECT 'a, b, c (x, y, z)' col1
             FROM DUAL)
SELECT t.col1,
       REPLACE(REGEXP_REPLACE(t.col1, '(\(.*\))|(,)', '\1\2\2'), ',,', '#') new_col
  FROM t;

Try this for comma etc
In the above query use '' instead of #
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

WITH t AS (SELECT 'a, b, c (x, y, z), a, (xx, yy, zz), x,' col1
             FROM dual)
SELECT t.col1
     , REGEXP_REPLACE(t.col1, '(\(.*?\))|,', '\1') new_col
  FROM t;

Try this replacing t with your table

slightwv (䄆 Netminder) Commented:
Can you post your code that produces the CSV?

I would suggest fixing it there instead of after the fact.

You can likely put a simple NVL call in the code that creates the CSV.

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
slightwv (䄆 Netminder) Commented:
>>You could also try coalesce...

How will coalesce remove 'null'/missing values in a CSV?
> How will coalesce remove 'null'/missing values in a CSV?

I thought the problem here with the NULLs.  I also wanted to see the code which generates the CSV ;-). If my solution is no way related i'll take mine back.
teaoneAuthor Commented:
this solution from anumoses' link worked:
trim(',' from regexp_replace(val, '( *, *){2,}', ','))
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
Oracle Database

From novice to tech pro — start learning today.