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!

Regexp_replace remove last character (comma)

PugzlyMar 29 2022

I have the following code, which groups emails for each customer that appears to be working fine except for a small caveat where there is a trailing comma at the end of each line, which I want to exclude.

I tried using regexp_replace with the following argument  
regexp_replace(str, '.$')  but I can't get past a syntax error.

Any help would be greatly appreciated. I am also open to any other solutions that can solve the problem.

select customer_id, listagg(email_id || '   ,   ') within group (order by customer_id) FROM (
select 1 as customer_id, 'hk@gmail.com' as email_id , 'primary' as usagetype from dual UNION
select 1 as customer_id, 'hk@tmail.com' as email_id , 'work' as usagetype from dual UNION
select 2 as customer_id, 'tt@tmail.com' as email_id , 'work' as usagetype from dual 
)group by customer_id;
This post has been answered by mathguy on Mar 29 2022
Jump to Answer
Comments
Post Details
Added on Mar 29 2022
8 comments
9,450 views